Submission #523361

#TimeUsernameProblemLanguageResultExecution timeMemory
523361Ahmed2meTable Tennis (info1cup20_tabletennis)C++17
87 / 100
3066 ms29656 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define ll long long #define fl cout.flush(); #define endl '\n' #define sp ' ' using namespace __gnu_pbds; using namespace std; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; inline void fileim(bool usaco,bool cs,bool cs2,char *s,char *s2) { if(usaco) { #define fin cin #define fout cout } if(cs){freopen( s, "r", stdin );} if(cs2){freopen( s2, "w", stdout );} } const int mxint = 2147483647 ; const ll MOD=1e9+7; const ll N=3e6; const double EPS=1e-6; vector<int>pr;int lp[1000001]; ll power(ll x, ll y) { ll ans=1;while(y){if(y&1){ ans=(ans*x)%MOD; }y/=2;x=(x*x)%MOD;}return ans; } ll bitcount(ll num){ ll rtrn=0;while(num){rtrn++;num=(num&(num-1));}return rtrn; } ll inv(ll x){return power(x , MOD-2);} void linear_seive() { for(int i=2;i<=N;i++) { if(!lp[i]){lp[i]=i;pr.push_back(i);} for(int j=0;j<pr.size()&&pr[j]<=lp[i]&&i*pr[j]<=N;j++){lp[i*pr[j]]=pr[j];} } } 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; set<ll>ans; while(i<j) { if(a[i]+a[j]==sum){ans.insert(a[i]);ans.insert(a[j]);i++;j--;continue;} if(a[i]+a[j]>sum){j--;continue;} if(a[i]+a[j]<sum){i++;continue;} } for(auto I:ans){cout<<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)-2*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); //cin>>t;//linear_seive();//fileim( 1,1,1, "hps.in","hps.out" ); cout<< fixed << setprecision(15) ;while(t--){solve();}return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'void linear_seive()':
tabletennis.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int j=0;j<pr.size()&&pr[j]<=lp[i]&&i*pr[j]<=N;j++){lp[i*pr[j]]=pr[j];}
      |                     ~^~~~~~~~~~
#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...