主要注意:following condition holds: yi - 1 < yi andyi > yi + 1.即可。答案不唯一。
#include <iostream> using namespace std; int a[205]; int main() { int n, k; while(cin >> n >>k) { for(int i = 0; i < 2 * n + 1; i++) cin >> a[i]; for(int i = 1; k; i += 2) if(a[i] - 1 > a[i - 1] && a[i] - 1 > a[i + 1]) { a[i]--; k--; } for(int i = 0; i < 2 * n; i++) cout << a[i] << " "; cout << a[2 * n] << endl; } return 0; }