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;
const int MAXN = 5*1e5+5;
int dp[MAXN];
vector<int> v;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,k; cin>>n>>k;
for(int i = 1; i < n; i++){
int a,b; cin>>a>>b;
}
for(int i = 0; i < k; i++){
int x;cin>>x;
v.push_back(x);
}
for(int i = k-1; i >= 0; i--){
dp[i] = dp[i+1]+1;
if(i != k && (v[i+1]-v[i])%2 == 0)dp[i] = min(dp[i],dp[i+2]+1);
}
cout<<dp[0]<<"\n";
int i = 0;
while(i < k){
if((v[i+1]-v[i])%2 == 1 || dp[i] == dp[i+1]+1){
cout<<v[i]<<" ";
i++;
}else{
cout<<v[i] + (v[i+1]-v[i])/2<<" ";
i += 2;
}
}cout<<"\n";
}
# | 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... |