이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define int long long
#define endl "\n"
const int N = 3e5,K = 400;
int num[N + 1],n,k;
vector<pair<int,int>> res;
map<int,int> mp;
inline void build(int sum,int l,int r) {
res.clear();
int curr = r - 1;
for(int i = l + 1;i < curr;i++) {
while(curr > i && num[i] + num[curr] > sum) curr--;
if(num[i] + num[curr] == sum) {
res.push_back({num[i],num[curr]});
curr--;
}
}
if((int)res.size() < n/2 - 1) {
return;
}
vector<int> kq;
for(int i = 0;i < n/2 - 1;i++) {
kq.push_back(res[i].first);
kq.push_back(res[i].second);
}
kq.push_back(num[l]);
kq.push_back(num[r]);
sort(kq.begin(),kq.end());
for(auto u : kq) {
cout<<u<<" ";
}
exit(0);
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n>>k;
int len = n + k;
for(int i = 1;i <= len;i++) {
cin>>num[i];
mp[num[i]] = i;
}
for(int i = 1;i <= k + 1 && i <= len;i++) {
int left = len - (k - i + 1);
for(int j = left;j <= len;j++) {
int sum = num[i] + num[j],cnt = 0;
for(int t = 1;t < i;t++) {
int x = mp[sum - num[t]];
cnt += (x > i && x < j);
}
for(int t = j + 1;t <= len;t++) {
int x = mp[sum - num[t]];
cnt += (x > i && x < j);
}
if(cnt > (k - (i - 1 + len - j))) continue;
build(num[i] + num[j],i,j);
}
}
return 0;
}
# | 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... |