Codeforces Round #374 (Div. 2) D. Maxim and Array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.