/*input
4 3
1 2 3 4 8 10 20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_sett;
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memsett(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
int arr[maxn];
int ar[maxn],l[maxn],r[maxn];
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,k;
cin>>n>>k;
REP(i,n+k) cin>>arr[i];
map<int,int> mp;
if(n>=3*k){
REP(i,2*k){
for(int j=n+k-1;j>=n-k;j--){
mp[arr[i]+arr[j]]++;
}
}
}
else{
REP(i,n+k){
REP(j,i) mp[arr[i]+arr[j]]=k;
}
}
for(auto x:mp){
if(x.s>=k){
int pp=0,lp=0,rp=0;
int s=x.f,ans=0;
REP(a,n+k){
while(pp>0 and ar[pp]+arr[a]>s) --pp;
if(pp>0 and ar[pp]+arr[a]==s){
++ans,l[lp++]=ar[pp],r[rp++]=arr[a];
}
else ar[++pp]=arr[a];
if(ans==(n/2)) break;
}
if(ans==(n/2)){
REP(i,n/2) cout<<l[n/2-i-1]<<' ';
REP(i,n/2) cout<<r[i]<<' ';
return 0;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
716 KB |
Output is correct |
2 |
Correct |
42 ms |
3248 KB |
Output is correct |
3 |
Correct |
35 ms |
3140 KB |
Output is correct |
4 |
Correct |
35 ms |
3204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
3276 KB |
Output is correct |
2 |
Correct |
36 ms |
3268 KB |
Output is correct |
3 |
Correct |
42 ms |
3268 KB |
Output is correct |
4 |
Correct |
36 ms |
3180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
12 ms |
972 KB |
Output is correct |
3 |
Correct |
3 ms |
972 KB |
Output is correct |
4 |
Correct |
7 ms |
1100 KB |
Output is correct |
5 |
Correct |
4 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
37 ms |
3256 KB |
Output is correct |
3 |
Correct |
43 ms |
3268 KB |
Output is correct |
4 |
Correct |
40 ms |
3160 KB |
Output is correct |
5 |
Correct |
40 ms |
3268 KB |
Output is correct |
6 |
Correct |
38 ms |
3212 KB |
Output is correct |
7 |
Correct |
39 ms |
3244 KB |
Output is correct |
8 |
Correct |
40 ms |
3276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
4584 KB |
Output is correct |
2 |
Correct |
389 ms |
30976 KB |
Output is correct |
3 |
Correct |
359 ms |
33984 KB |
Output is correct |
4 |
Correct |
238 ms |
29960 KB |
Output is correct |
5 |
Correct |
198 ms |
11588 KB |
Output is correct |
6 |
Correct |
81 ms |
4932 KB |
Output is correct |
7 |
Correct |
226 ms |
26692 KB |
Output is correct |
8 |
Correct |
221 ms |
28868 KB |
Output is correct |