Submission #762392

# Submission time Handle Problem Language Result Execution time Memory
762392 2023-06-21T11:21:47 Z voliaanyk Table Tennis (info1cup20_tabletennis) C++14
0 / 100
15 ms 1492 KB
#include "bits/stdc++.h"
using namespace std;
 
#define DIM 160007
#define DIM2 2007
#define fi first
#define se second
#define mod 1000000007
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

ll n, k, a[DIM];
vector<ll> res;
map<ll, ll> m;


bool check(ll d){
    
    ll l = 1, r = n+k;
    
    res.clear();
    
    while(l<r){
        
        if(a[r]+a[l] == d){
            res.push_back(a[l]); res.push_back(a[r]);
            r--;
            l++;
        }
        else if(a[r] + a[l] > d) r--;
        else l++;
        
        if(res.size()>=n) return true;
        
    }
    return false;
    
}


 
int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin>>n>>k;
    for(int i=1;i<=n+k;i++){
        cin>>a[i];
    }
    
    for(int i=1;i<=k;i++){
        for(int j=n;j>=n-k+1;j--){
            if(i<j) m[a[j]+a[i]]++;
        }
    }
    
    for(auto r:m){
        
        if(r.se < k) continue;
        if(check(r.fi)){
            sort(res.begin(), res.end());
            for(int i=0;i<res.size();i++){
                cout<<res[i]<<" ";
            }
            cout<<endl;
            return 0;
        }
    }
    
    
    return 0;
}

/*
 4 3
 1 2 3 4 8 10 20
 
 
 4 2
 1 2 3 4 5 6
 */

Compilation message

tabletennis.cpp: In function 'bool check(ll)':
tabletennis.cpp:35:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   35 |         if(res.size()>=n) return true;
      |            ~~~~~~~~~~^~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for(int i=0;i<res.size();i++){
      |                         ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 852 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 1492 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 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
3 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 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 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -