Submission #523377

#TimeUsernameProblemLanguageResultExecution timeMemory
523377Ahmed2meTable Tennis (info1cup20_tabletennis)C++17
87 / 100
3081 ms38252 KiB
#include <bits/stdc++.h> using namespace std; long long t=1,n,m; long long a[200020]; bool good(long long sum) { long long i=1,j=n+m; long long 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(long long sum) { long long i=1;long long j=n+m; vector<long long>ans; long long 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++){printf("%d%c",ans[i],' ');} return; } void solve() { scanf("%d",&n);scanf("%d",&m);map<long long,bool>mp; for(int i=1;i<=n+m;i++){cin>>a[i];} for(int i=1;i<=min(n,2*m);i++) { for(int j=max(1ll,(n-m+1));j<=n+m;j++) { mp[(a[i]+a[j])]=true; } } for(auto I:mp){if(good(I.first)){print_ans(I.first);return;}} } int main() { while(t--){solve();}return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'void print_ans(long long int)':
tabletennis.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0;i<ans.size();i++){printf("%d%c",ans[i],' ');}
      |                 ~^~~~~~~~~~~
tabletennis.cpp:34:44: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wformat=]
   34 |     for(int i=0;i<ans.size();i++){printf("%d%c",ans[i],' ');}
      |                                           ~^
      |                                            |
      |                                            int
      |                                           %lld
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:40:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   40 |     scanf("%d",&n);scanf("%d",&m);map<long long,bool>mp;
      |            ~^  ~~
      |             |  |
      |             |  long long int*
      |             int*
      |            %lld
tabletennis.cpp:40:28: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   40 |     scanf("%d",&n);scanf("%d",&m);map<long long,bool>mp;
      |                           ~^  ~~
      |                            |  |
      |                            |  long long int*
      |                            int*
      |                           %lld
tabletennis.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d",&n);scanf("%d",&m);map<long long,bool>mp;
      |     ~~~~~^~~~~~~~~
tabletennis.cpp:40:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d",&n);scanf("%d",&m);map<long long,bool>mp;
      |                    ~~~~~^~~~~~~~~
#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...