This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
int n,k;
vi a,ans;
bool solve(int x){
int l=0,r=n+k-1;ans.clear();
while(l<r&&ans.size()<n){
while(l<r&&a[l]+a[r]>x)r--;
if(l<r&&a[l]+a[r]==x){
ans.PB(a[l]);ans.PB(a[r]);
}
if(r-l+1+ans.size()<n)break;
l++;
}
sort(ans.begin(),ans.end());
return ans.size()==n;
}
int main() {
cin>>n>>k;a.resize(n+k);
REP(i,0,n+k)cin>>a[i];
REP(i,0,k+1)REP(j,n-1,n+k)if(solve(a[i]+a[j])){
for(auto u:ans)cout<<u<<" ";
return 0;
}
return 0;
}
Compilation message (stderr)
tabletennis.cpp: In function 'bool solve(int)':
tabletennis.cpp:29:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
29 | while(l<r&&ans.size()<n){
| ~~~~~~~~~~^~
tabletennis.cpp:34:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if(r-l+1+ans.size()<n)break;
| ~~~~~~~~~~~~~~~~^~
tabletennis.cpp:38:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
38 | return ans.size()==n;
| ~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |