Exercises
Simulation questions
Although it is a big simulation problem, but it is a test of the active degree of thinking.
You know how to do it when you first start doing it. But there are a lot of things in your mind. Categorical enumeration always confuses itself
The question taught me to think carefully about the way we classify
This question. Judging by the odd number of enumerated negative numbers
is odd: Then the absolute value of the smallest number, if it is positive, +x, is negative,-X;
is even: the number that makes the absolute minimum. Change the symbol, if positive-X, negative +x.
Code:
#include <bits/stdc++.h>#defineMAXN 200010#defineMoD 1000000007#definell Long Long#definePB Push_back#defineFS First#defineSe Secondusing namespacestd;Const intinf=1e9+7; ll A[MAXN];p air<ll,int>P[MAXN];p riority_queue<pair<ll,int, Vector<pair<ll,int>, Greater<pair<ll,int> > >Q;intok=1;intMain () {intn,k,x; scanf ("%d%d%d",&n,&k,&x); for(intI=1; i<=n;i++) {scanf ("%lld",&A[i]); if(a[i]<0) ok^=1; p[i].se=i; P[i].fs=ABS (A[i]); Q.push (P[i]); } while(k) {pair<ll,int> now=Q.top (); Q.pop (); if(OK) {if(a[now.se]>=0) {a[now.se]-=x; if(a[now.se]<0) ok^=1; } Else{a[now.se]+=x; if(a[now.se]>=0) ok^=1; } Now.fs=ABS (a[now.se]); Q.push (now); } Else { if(a[now.se]>=0) a[now.se]+=x; Elsea[now.se]-=x; Now.fs=ABS (a[now.se]); Q.push (now); } k--; } for(intI=1; i<=n;i++) printf ("%lld", A[i]);}
Codeforces Round #374 (Div. 2) D. Maxim and Array