This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, k;
vector <int> v;
int main(){
cin >> n >> k;
for(int i = 1;i < n;i++){
int a, b;
cin >> a >> b;
}
for(int i = 1;i <= k;i++){
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
int res = v.size();
vector <int> ans = v;
int resp = 0;
vector <int> anss;
for(int i = 0;i < k;i++){
if(i < k-1 and (v[i+1]+v[i]) % 2 == 0){
anss.push_back((v[i+1]+v[i])/2);
resp++;i++;
}
else
{
resp++;
anss.push_back(v[i]);
}
}
if(res > resp){
ans = anss;
res = resp;
}
anss.clear();
reverse(v.begin(), v.end());
resp = 0;
for(int i = 0;i < k;i++){
if(i < k-1 and (v[i+1]+v[i]) % 2 == 0){
anss.push_back((v[i+1]+v[i])/2);
resp++;i++;
}
else {
resp++;
anss.push_back(v[i]);
}
}
if(res > resp){
ans = anss;
res = resp;
}
anss.clear();
cout << ans.size() << endl;
for(auto x : ans){
cout << x << ' ';
}
}
# | 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... |