제출 #386562

#제출 시각아이디문제언어결과실행 시간메모리
386562fadi57Table Tennis (info1cup20_tabletennis)C++14
100 / 100
755 ms5476 KiB
#include<bits/stdc++.h> using namespace std; const int mx=2e5+10; typedef long long ll; const int inf=1e9+3e5; int a[mx]; map<int,int>mp;int n,k,z; bool check(int s){ int l=0;int r=z-1; int cnt=n/2; while(l<r){ if(cnt==0){break;} if(((r-l+1)/2)<cnt){break;} if(a[l]+a[r]>s){r--;} else if(a[l]+a[r]<s){l++;} else{ l++; r--; cnt--; } } if(cnt==0){return 1;} return 0; } int main(){ cin>>n>>k; z=n+k; for(int i=0;i<n+k;i++){ cin>>a[i]; } /* 3 1 1 1 1 1*/ int teams=n/2; int aa;int bb; vector<int>v; for(int i=0;i<=k;i++){ for(int j=n-1;j<z;j++){ v.push_back(a[i]+a[j]); } } sort(v.begin(),v.end()); int sum; for(auto it:v){ if(check(it)){ sum=it;break; } }//cout<<sum; int l=0;int r=z-1; int cnt=n/2; vector<int>o; while(l<r){ if(cnt==0){break;} if(a[l]+a[r]>sum){r--;} else if(a[l]+a[r]<sum){l++;} else{ // cout<<a[l]<<" "<<a[r]<<" "; o.push_back(a[l]); o.push_back(a[r]); l++; r--; cnt--; } }sort(o.begin(),o.end()); for(auto it:o){ cout<<it<<" "; } }

컴파일 시 표준 에러 (stderr) 메시지

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:42:6: warning: unused variable 'teams' [-Wunused-variable]
   42 |  int teams=n/2;
      |      ^~~~~
tabletennis.cpp:43:6: warning: unused variable 'aa' [-Wunused-variable]
   43 |  int aa;int bb;
      |      ^~
tabletennis.cpp:43:13: warning: unused variable 'bb' [-Wunused-variable]
   43 |  int aa;int bb;
      |             ^~
tabletennis.cpp:68:10: warning: 'sum' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |     else if(a[l]+a[r]<sum){l++;} else{
      |          ^~
#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...