Submission #523367

#TimeUsernameProblemLanguageResultExecution timeMemory
523367Ahmed2meTable Tennis (info1cup20_tabletennis)C++17
87 / 100
3015 ms29888 KiB
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define sp ' ' using namespace std; ll t=1,n,m,a[200020]; bool good(ll sum) { ll i=1,j=n+m; ll cnt=false; while(i<j) { if(a[i]+a[j]==sum){cnt++;i++;j--;continue;} if(a[i]+a[j]>sum){j--;continue;} if(a[i]+a[j]<sum){i++;continue;} } return cnt>=(n/2); } void print_ans(ll sum) { ll i=1;ll j=n+m; vector<ll>ans; ll counter=false; while(i<j) { if(counter>=(n/2)){break;} if(a[i]+a[j]==sum){counter++;ans.push_back(a[i]);ans.push_back(a[j]);i++;j--;continue;} if(a[i]+a[j]>sum){j--;continue;} if(a[i]+a[j]<sum){i++;continue;} } sort(ans.begin(),ans.end()); for(int i=0;i<ans.size();i++){cout<<ans[i]<<sp;} return; } void solve() { cin>>n>>m; for(int i=1;i<=n+m;i++){cin>>a[i];} set<int>st;sort(a+1,a+n+m+1); for(int i=1;i<=min(n,2*m);i++) { for(int j=max(1ll,(n-m+1));j<=n+m;j++) { st.insert(a[i]+a[j]); } } for(auto I:st){if(good(I)){print_ans(I);return;}} } int main() { ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL); while(t--){solve();}return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'void print_ans(long long int)':
tabletennis.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<ans.size();i++){cout<<ans[i]<<sp;}
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...