#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){
resp++;i++;
anss.push_back((v[i+1]+v[i])/2);
}
else
{
resp++;
ans.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){
resp++;i++;
anss.push_back((v[i+1]+v[i])/2);
}
else {
resp++;
anss.push_back(v[i]);
}
}
if(res > resp){
ans = anss;
res = resp;
}
anss.clear();
cout << res << endl;
for(auto x : ans){
cout << x << ' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
167 ms |
408 KB |
Extra information in the output file |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
166 ms |
596 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |