#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 << ' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
344 KB |
Output is correct |
2 |
Correct |
154 ms |
348 KB |
Output is correct |
3 |
Correct |
140 ms |
348 KB |
Output is correct |
4 |
Correct |
210 ms |
6164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Sheep 3030 not protected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Sheep 128 not protected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
145 ms |
424 KB |
Sheep 54 not protected |
2 |
Halted |
0 ms |
0 KB |
- |