Submission #523380

#TimeUsernameProblemLanguageResultExecution timeMemory
523380Ahmed2meTable Tennis (info1cup20_tabletennis)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int t=1,n,m; int a[200020]; bool good(int sum) { int i=1,j=n+m; int 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(int sum) { int i=1;int j=n+m; vector<int>ans; int 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++){scanf("%d",&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(int)':
tabletennis.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<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: In function 'void solve()':
tabletennis.cpp:44:34: error: no matching function for call to 'max(long long int, int)'
   44 |         for(int j=max(1ll,(n-m+1));j<=n+m;j++)
      |                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from tabletennis.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:44:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |         for(int j=max(1ll,(n-m+1));j<=n+m;j++)
      |                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from tabletennis.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:44:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |         for(int j=max(1ll,(n-m+1));j<=n+m;j++)
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tabletennis.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:44:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |         for(int j=max(1ll,(n-m+1));j<=n+m;j++)
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tabletennis.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:44:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |         for(int j=max(1ll,(n-m+1));j<=n+m;j++)
      |                                  ^
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;
      |                    ~~~~~^~~~~~~~~
tabletennis.cpp:41:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     for(int i=1;i<=n+m;i++){scanf("%d",&a[i]);}
      |                             ~~~~~^~~~~~~~~~~~