#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>;
int n,k;
void slv(deque<int>dq,int p){
int kk=k;
deque<int>a,b;
while(dq.size()){
if(dq.size()==1){
kk--;
break;
}
int f=dq.back();
dq.pop_back();
auto it=lower_bound(dq.begin(),dq.end(),p-f);
if(it==dq.end()||*it!=p-f){
kk--;
continue;
}else{
while(dq.front()!=*it){
dq.pop_front();
kk--;
}
a.push_back(dq.front());
b.push_front(f);
dq.pop_front();
}
}
if(kk==0){
for(auto &i:a)cout<<i<<' ';
for(auto &i:b)cout<<i<<' ';
exit(0);
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;
deque<int>dq(n+k);
for(auto &i:dq)cin>>i;
srand(543634);
map<int,int>mp;
vector<pair<int,int>>v;
for(int i=0;i<2000000;i++)mp[abs(dq[rand()%n]+dq[rand()%n])]++;
for(auto &i:mp)v.push_back({i.second,i.first});
sort(v.begin(),v.end());
for(int i=v.size()-1;i>=0;i--){
slv(dq,v[i].second);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1462 ms |
61944 KB |
Output is correct |
2 |
Correct |
278 ms |
964 KB |
Output is correct |
3 |
Correct |
1722 ms |
74232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1274 ms |
4248 KB |
Output is correct |
2 |
Correct |
2786 ms |
161432 KB |
Output is correct |
3 |
Correct |
2593 ms |
161520 KB |
Output is correct |
4 |
Correct |
2568 ms |
161556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
153632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
316 KB |
Output is correct |
2 |
Incorrect |
248 ms |
684 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
320 KB |
Output is correct |
2 |
Correct |
102 ms |
304 KB |
Output is correct |
3 |
Correct |
93 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
300 KB |
Output is correct |
2 |
Correct |
306 ms |
2420 KB |
Output is correct |
3 |
Correct |
1856 ms |
107836 KB |
Output is correct |
4 |
Correct |
1671 ms |
74916 KB |
Output is correct |
5 |
Correct |
247 ms |
844 KB |
Output is correct |
6 |
Correct |
232 ms |
1388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
324 KB |
Output is correct |
2 |
Correct |
2663 ms |
161536 KB |
Output is correct |
3 |
Correct |
2646 ms |
161556 KB |
Output is correct |
4 |
Execution timed out |
3041 ms |
138932 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
212 KB |
Output is correct |
2 |
Correct |
2819 ms |
161740 KB |
Output is correct |
3 |
Correct |
2833 ms |
161452 KB |
Output is correct |
4 |
Correct |
2713 ms |
161524 KB |
Output is correct |
5 |
Correct |
2528 ms |
145256 KB |
Output is correct |
6 |
Execution timed out |
3037 ms |
27996 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |