This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//####################
//Binome_Equilibres
//####################
#include<bits/stdc++.h>
using namespace std;
int n,k;
vector<int> nums;
bool possible(int start,int end,int K){
int target = nums[start]+nums[end];
vector<int> S,E;
S.push_back(nums[start]);
E.push_back(nums[end]);
start++;
end--;
while(start<end && K>=0){
int sum = nums[start]+nums[end];
if(sum>target){
K--;
end--;
}else if(sum<target){
K--;
start++;
}else{
S.push_back(nums[start]);
E.push_back(nums[end]);
start++;
end--;
}
}
if(K<0)return false;
while(n!=(int(S.size()+E.size()))){
S.erase(S.begin());
E.erase(E.begin());
}
for(int v:S)cout<<v<<' ';
reverse(E.begin(),E.end());
for(int v:E)cout<<v<<' ';
cout<<'\n';
return true;
}
signed main(){
cin>>n>>k;
nums.resize(n+k);
for(int i=0;i<n+k;i++){
cin>>nums[i];
}
for(int i=0;i<=k;i++){
int taked = i;
for(int j=n+k-1;j>=0 && taked<=k;j--){
if(possible(i,j,k-taked)){
return 0;
}
taked++;
}
}
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... |