Submission #481814

# Submission time Handle Problem Language Result Execution time Memory
481814 2021-10-22T01:10:00 Z Yazan_Alattar Table Tennis (info1cup20_tabletennis) C++14
0 / 100
21 ms 3160 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector <int> v;
int n, k, a[M];
bool vist[M];

int solve(int sum)
{
    int l = 1, r = n + k;
    while(l < r){
        if(a[l] + a[r] == sum){
            ++l;
            --r;
        }
        else if(a[l] + a[r] > sum){
            v.pb(r);
            --r;
        }
        else{
            v.pb(l);
            ++l;
        }
    }
    if(l == r) v.pb(l);
    return v.size() == k;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n + k; ++i) cin >> a[i];
    sort(a + 1, a + n + k + 1);
    int res = solve(a[1] + a[n + k]);
    if(res == 0) res = solve(a[2] + a[n + k]);
    if(res == 0) res = solve(a[1] + a[n + k - 1]);
    if(res == 0) res = solve(a[2] + a[n + k - 1]);
    for(auto i : v) vist[i] = 1;
    for(int i = 1; i <= n + k; ++i) if(!vist[i]) cout << a[i] << " ";
    cout << endl;
    return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)

Compilation message

tabletennis.cpp: In function 'int solve(int)':
tabletennis.cpp:48:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |     return v.size() == k;
      |            ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 588 KB Output is correct
2 Incorrect 20 ms 3064 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 3160 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -