Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer i (1 ≤ i ≤ n) and replaces the i-th element of array ai either with ai + x or with ai - x. Please note that the operation may be applied more than once to the same position.

Maxim is a curious minimalis, thus he wants to know what is the minimum value that the product of all array elements (i.e. ) can reach, if Maxim would apply no more than koperations to it. Please help him in that.

Input

The first line of the input contains three integers n, k and x (1 ≤ n, k ≤ 200 000, 1 ≤ x ≤ 109) — the number of elements in the array, the maximum number of operations and the number invented by Maxim, respectively.

The second line contains n integers a1, a2, ..., an () — the elements of the array found by Maxim.

Output

Print n integers b1, b2, ..., bn in the only line — the array elements after applying no more than k operations to the array. In particular,  should stay true for every 1 ≤ i ≤ n, but the product of all array elements should be minimum possible.

If there are multiple answers, print any of them.

Examples

Input
5 3 1
5 4 3 5 2
Output
5 4 3 5 -1 
 
思路:
如果负数个数为偶数,想办法让其变成奇数.
如果不能变为奇数,则不做任何变化,进入下一步.如果可以,控制其刚好变为奇数即可.
如果本身就是奇数,则不做任何变化.
 
接下来进行k步操作.
如果当前负数个数为奇数,则想办法使绝对值之积极可能大,每次使绝对值最小的数字的绝对值加上x即可.
如果当前负数个数为偶数,则想办法使绝对值之积极可能小,每次使绝对值最小的数字的绝对值减去x即可.
此操作使用优先队列维护.
 
______________
(a-x) * b = a*b-b*x
显然 当a<b时优于 a>b
 
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int loveisblue = ;
const int maxn = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int n,k;
struct node{
ll num,absnum;
int id;
bool operator<(const node &p)const{
return p.absnum<absnum;
}
}a[maxn];
priority_queue<node>q;
ll ans[maxn];
int main() {
// ios::sync_with_stdio(false);
// freopen("in.txt", "r", stdin); int n,k;
ll x;
scanf("%d%d%lld",&n,&k,&x);
for(int i=;i<=n;i++){
ll num;
scanf("%lld",&num);
a[i]=node{num,abs(num),i};
}
sort(a+,a++n);
int fu = ;
for(int i=;i<=n;i++){
if(a[i].num<){
fu++;
}
}
if(fu%==){
if(x*k>=a[n].absnum){
int p = min(1ll*k,a[n].absnum/x+);
k-=p;
if(a[n].num<){
a[n].num+=p*x;
a[n].absnum = abs(a[n].num);
}else{
a[n].num-=p*x;
a[n].absnum = abs(a[n].num);
}
}
}
fu = ;
for(int i=;i<=n;i++){
if(a[i].num<){
fu++;
}
}
for(int i=;i<=n;i++){
q.push(a[i]);
}
while (k--){
node exa = q.top();
q.pop();
if(fu&){
if(exa.num<){
exa.num-=x;
exa.absnum+=x;
}else{
exa.num+=x;
exa.absnum+=x;
}
}else{
if(exa.num<){
exa.num+=x;
exa.absnum-=x;
}else{
exa.num-=x;
exa.absnum-=x;
}
}
q.push(exa);
}
while (!q.empty()){
node exa = q.top();
q.pop();
ans[exa.id]=exa.num;
}
for(int i=;i<=n;i++){
printf("%lld ",ans[i]);
}
return ;
}

CodeForces - 721D Maxim and Array (贪心)的更多相关文章

  1. CodeForces 721D Maxim and Array

    贪心,优先队列. 先看一下输入的数组乘积是正的还是负的. ①如果是负的,也就是接下来的操作肯定是让正的加大,负的减小.每次寻找一个绝对值最小的数操作就可以了. ②如果是正的,也是考虑绝对值,先操作绝对 ...

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

    D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...

  3. Codeforces Round #374 (Div. 2) D. Maxim and Array —— 贪心

    题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...

  4. Codeforces F. Maxim and Array(构造贪心)

    题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #374 (Div. 2) D. Maxim and Array 线段树+贪心

    D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  7. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  8. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  9. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

随机推荐

  1. 【风马一族_mysql】mysql基本指令

    船停在港湾是很安全的,但那不是造船的目的! 用户 创建用户 mysql>grant 权限(select,insert,update,delete) on  数据库.数据表  to  用户名@电脑 ...

  2. “龙井”开箱评测 |Alibaba Dragonwell 新手上路指南

    作者|阿里云智能事业群 高级技术专家 陆传胜 阿里巴巴有着最丰富的 Java 应用场景,覆盖电商,金融,物流等众多领域,是世界上最大的 Java 用户之一. 2019 年 3 月 21 日,阿里巴巴在 ...

  3. 使用 docker-compose 安装 MySQL 5.5 记录

    使用 docker-compose 安装 MySQL 5.5 记录 安装 Docker-Compose 在 Centos 中安装 Docker 倒是很简单. 但是安装 docker-compose 遇 ...

  4. jq 添加内容

    向页面动态添加内容,一般用于动态网页,需要即时请求数据,并更新在页面上,使用append()更多一些,empty() - 清空所有子元素,remove() - 清除自身所有子元素. append() ...

  5. python 调用API时异常捕获的技巧

  6. Nginx 缓存代理

    访问ArcGIS官网的地图瓦片太慢.想到可用NIGIX代理. Nginx是Linux下http代理软件,Windows下也有. 以下为配置方法,注意红色部分. 1.需要在本地proxy_cache_p ...

  7. SDUT-2116_数据结构实验之链表一:顺序建立链表

    数据结构实验之链表一:顺序建立链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入N个整数,按照输入的顺序建立单链 ...

  8. js+canvas制作前端验证码

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. oracle函数 NLS_INITCAP(x[,y])

    [功能]返回字符串并将字符串的第一个字母变为大写,其它字母小写; [参数]x字符型表达式 [参数]Nls_param可选, 查询数据级的NLS设置:select * from nls_database ...

  10. 05Redis入门指南笔记(持久化)

    Redis的强劲性能很大程度上是由于将所有数据都存储在了内存中,然而当Redis重启后,所有存储在内存中的数据就会丢失.在一些情况下,希望Redis能将数据从内存中以某种形式同步到硬盘中,使得重启后可 ...