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

• -18

 » 2 months ago, # |   0 instead of downvoting,help me
 » 2 months ago, # | ← Rev. 2 →   0 I am not sure about what you are trying to do inside the double nested loops, but the problem has a simple O(n) solution with a single loop and without sorting the array. Note that the array size is 2*n+1, not n. Check the following solution if interested.123568084
•  » » 2 months ago, # ^ |   -8 how is it so simple? are u a grandmaster?
•  » » » 2 months ago, # ^ |   0 He's trying to help, at least check his solution to see if he is right.
 » 2 months ago, # | ← Rev. 2 →   0 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; } 
 » 2 months ago, # |   0 gawd, just see the editorial if not getting the correct logic or go see other's code to learn different approaches