Блог пользователя hrithox_1729

Автор hrithox_1729, история, 6 лет назад, По-английски

include

include

include

include

include

include

include

include

define ll long long

using namespace std;

int main() {

ifndef ONLINE_JUDGE

freopen("in.txt", "r", stdin);
freopen("ou.txt", "w", stdout);

endif

int t; cin >> t;
while (t--) {
    ll n, k; cin >> n >> k;
    set<ll> p;

    vector<pair<ll, ll> > v(n);
    int a[n];
    for (ll i = 0; i < n; i++) {
       cin >> v[i].first;
       v[i].second = i;
       a[i] = v[i].first;
    }
    sort(v.begin(), v.end());
    ll l = 0, r = v.size() - 1;
    while (l <= r) {
       ll ans = v[l].first + v[r].first;
       if (ans == k) {
         p.insert(v[l].second);
         l++;
         r--;
       }
       else if (ans > k) {
         r--;
       }
       else
         l++;
    }
    for (int i = 0; i < n; i++) {
       if (p.find(i) != p.end()) {
         cout << 0 << " ";
       }
       else
         cout << 1 << " ";
    }
    cout << endl;
}
return 0;

} my logic was that making pairs of a having sum eaual to t then picking first numbers from each pair and putting it in one array and rest and second number in pairs in another array.. eg 123456 and t=7 1 6 ,2 5,3 4 then putting 1 2 3 in one array and rest in another array eg 3 3 3 and t=6 3 3 then putting 3 in one array and 3 3 in another array

I am getting wrong anser in test case 2 help me plsssss...

  • Проголосовать: нравится
  • -29
  • Проголосовать: не нравится