/*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;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD2=3006703054056749LL;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-4;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll mult(ll a,ll b){
return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
ll res=1;
while(b){
if(b&1) res=mult(res,a);
a=mult(a,a);
b/=2;
}
return res;
}
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];
unordered_map<int,int> mp;
if(n>=3*k){
REP(i,n+k){
for(int j=n+k-1;j>=max(0,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 and ar[pp]+arr[a]>s) --pp;
if(pp 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;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
460 KB |
Output is correct |
2 |
Correct |
18 ms |
460 KB |
Output is correct |
3 |
Correct |
20 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
623 ms |
1596 KB |
Output is correct |
2 |
Execution timed out |
3059 ms |
13592 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3049 ms |
23044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
588 KB |
Output is correct |
2 |
Correct |
14 ms |
844 KB |
Output is correct |
3 |
Correct |
11 ms |
972 KB |
Output is correct |
4 |
Correct |
11 ms |
972 KB |
Output is correct |
5 |
Correct |
18 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
10 ms |
972 KB |
Output is correct |
3 |
Correct |
15 ms |
3448 KB |
Output is correct |
4 |
Correct |
19 ms |
2908 KB |
Output is correct |
5 |
Correct |
20 ms |
2624 KB |
Output is correct |
6 |
Correct |
13 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3095 ms |
215400 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
4956 KB |
Output is correct |
2 |
Execution timed out |
3093 ms |
196248 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |