Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

### nrg_aceu's blog

By nrg_aceu, history, 2 months ago, can someone help me with this problem https://codeforces.com/contest/218/problem/A my solution is this https://pastebin.com/r0ppiqGh idk what is wrong with it because ive been debugging for 45 mins Comments (6)
 » 2 months ago, # | ← Rev. 2 →   In this problem, you need to reduce the array elements with odd index(1,3,5,7,9,...) because index starts from 0 and we need to reduce the alternate numbers starting from 2nd number. To do that, just traverse the array and reduce k alternate elements starting from index 1 if r[i] — r[i — 1] > 1 && r[i] — r[i + 1] > 0 is fulfilled. #include using namespace std; int main() { int n, k; cin >> n >> k; int r[2 * n + 1]; for (int i = 0 ; i < (2 * n + 1) ; i ++) { cin >> r[i]; } for (int i = 1 ; i < (2 * n + 1) ; i += 2) { if (k > 0 && (r[i] - r[i - 1] > 1) && (r[i] - r[i + 1] > 1)) { r[i] --; k --; } else if (k == 0) break; } for (int i = 0 ; i < (2 * n + 1) ; i ++) { cout << r[i] << " "; } cout << "\n"; return 0; }