Submission #791056

# Submission time Handle Problem Language Result Execution time Memory
791056 2023-07-23T11:28:51 Z Andrey Table Tennis (info1cup20_tabletennis) C++14
0 / 100
150 ms 3092 KB
#include <bits/stdc++.h>
using namespace std;

int n,k;
vector<int> ans(0);
vector<int> haha(0);

bool check(int a) {
    ans.clear();
    int l = 0,r = n+k-1;
    while(l < r) {
        while(r > l && haha[l]+haha[r] > a) {
            r--;
        }
        if(r <= l) {
            return false;
        }
        if(haha[r]+haha[l] == a) {
            ans.push_back(haha[l]);
            ans.push_back(haha[r]);
            if(ans.size() == n) {
                return true;
            }
        }
        l++;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> k;
    int a;
    for(int i = 0; i < n+k; i++) {
        cin >> a;
        haha.push_back(a);
    }
    for(int i = 0; i < k; i++) {
        for(int j = n+k-1; j >= n && j > i; j--) {
            if(check(haha[i]+haha[j])) {
                sort(ans.begin(),ans.end());
                for(int y = 0; y < n; y++) {
                    cout << ans[y] << " ";
                }
                cout << endl;
                return 0;
            }
        }
    }
    return 0;
}

Compilation message

tabletennis.cpp: In function 'bool check(int)':
tabletennis.cpp:21:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |             if(ans.size() == n) {
      |                ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 724 KB Output is correct
2 Incorrect 12 ms 1492 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3092 KB Output is correct
2 Incorrect 12 ms 1492 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 150 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -