目录

    • Codeforces Round #717 (Div. 2)-A. Tit for Tat
      • Problem Description
      • Input
      • Output
      • Sample Input
      • Sample Onput
      • Note
  • 题目大意
  • 题目分析
  • AC代码

Codeforces Round #717 (Div. 2)-A. Tit for Tat

传送门
Time Limit: 1 second
Memory Limit: 256 megabytes

Problem Description

Given an array aaa of length nnn, you can do at most kkk operations of the following type on it:

What is lexicographically the smallest array you can obtain?

An array xxx is lexicographically smaller than an array yyy if there exists an index iii such that xi<yix_i<y_ixi​<yi​, and xj=yjx_j=y_jxj​=yj​ for all 1≤j<i1 \le j < i1≤j<i. Less formally, at the first index iii in which they differ, xi<yix_i<y_ixi​<yi​.

Input

The first line contains an integer ttt (1≤t≤201 \le t \le 201≤t≤20) – the number of test cases you need to solve.

The first line of each test case contains 222 integers nnn and kkk (2≤n≤1002 \le n \le 1002≤n≤100, 1≤k≤100001 \le k \le 100001≤k≤10000) — the number of elements in the array and the maximum number of operations you can make.

The second line contains nnn space-separated integers a1a_1a1​, a2a_2a2​, …\ldots…, ana_{n}an​ (0≤ai≤1000 \le a_i \le 1000≤ai​≤100) — the elements of the array aaa.

Output

For each test case, print the lexicographically smallest array you can obtain after at most kkk operations.

Sample Input

2
3 1
3 1 4
2 10
1 0

Sample Onput

2 1 5
0 1

Note

In the second test case, we start by subtracting 111 from the first element and adding 111 to the second. Then, we can’t get any lexicographically smaller arrays, because we can’t make any of the elements negative.


题目大意

给你含有nnn个非负整数的数组,你可以对他进行kkk此操作。
每次操作可以选择两个数,并把其中的一个数减一,另一个数加一。
问你最多kkk次操作后,这些数最小字典序是什么样子。


题目分析

要使字典序最小,就要使前面的数尽量小。
但总和不变,因此就要使后面的数尽量大。
所以每次操作,就把尽可能考前的正数减一,最后一个数加一,知道kkk次就行了。


AC代码

#include <bits/stdc++.h>
using namespace std;
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
int a[1010];
int main()
{int N;cin>>N;while(N--){int n,k;cin>>n>>k;fi(i,0,n)//for(int i=0;i<n;i++)cd(a[i]);//scanf("%d", &a[i]);int loc=0;//下标从第一个元素开始while(loc<n-1&&k>0)//第一个大于0的数不是最后一个 且 还有剩余的操作次数if(a[loc])//如果这个数不是0a[loc]--,a[n-1]++,k--;//这个数-1,最后一个数+1,剩余操作次数-1else//否则这个数是0loc++;//下标加一,下次处理下一个数fi(i,0,n)printf("%d ",a[i]);puts("");//换行}return 0;
}

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/116354382

Codeforces Round #717 (Div. 2)-A. Tit for Tat-题解相关推荐

  1. Codeforces Round #717 (Div. 2)

    Codeforces Round #717 (Div. 2) CodeForces 1516 题号 题目 知识点 A Tit for Tat 贪心 B AGAGA XOOORRR 思维题 C Baby ...

  2. Codeforces Round #717 (Div. 2) D. Cut 倍增

    传送门 文章目录 题意: 思路: 题意: 给定长度为nnn的序列,有qqq个询问,每次询问一个区间,输出至少将这个区间分成多少个连续区间才能使每个区间内的数互质. 思路: 首先要判断互质,这个比较容易 ...

  3. Codeforces Round #717 (Div. 2) D(倍增dp)

    Codeforces Round #717 (Div. 2) D 题意:n个数 q个询问,每一个询问有l和r,问你l到r这段区间中最少能分成几段,每一段中的数都是互质的. 思路:首先预处理出每一个点向 ...

  4. 【Codeforces Round #767 (Div. 2)】 C. Meximum Array 题解

    [Codeforces Round #767 (Div. 2) ]C. Meximum Array 题解 1629C: Meximum Array 题解 [Codeforces Round #767 ...

  5. Codeforces Round #717 Div.2

    凌晨睡不着 练cf算了 A. Tit for Tat 题意:一行数字,最多k个操作,每次操作可以把不同的两个数一个+1一个-1,并且操作完数字不能为负,问字典序最小的方案. sb题,选头部数字减尾部数 ...

  6. Codeforces Round #717 (Div. 2)(ABCD)

    A. Tit for Tat 从前往后枚举,把前面的数减到0,然后给最后一个数加上去.操作次数没了就停止 #include<bits/stdc++.h> using namespace s ...

  7. Codeforces Round #717 (Div. 2) 1516 A. Tit for Tat(模拟)

    LINK 记∑i=1n−1ai=sum\sum\limits_{i=1}^{n-1}a_i=sumi=1∑n−1​ai​=sum 如果可以,我们可以让前n−1n-1n−1个数都减成000,然后ana_ ...

  8. Codeforces Round #744 (Div. 3)【A-D E的题解】

    目录 A. Elections[800 / 模拟] B. Make it Divisible by 25[900 / 思维] C. Save More Mice[1000 / 贪心] D1. All ...

  9. Codeforces Round #411 (Div. 1)(A~D)题解

    题目链接: #411 (Div. 1) 差点翻船. 题解: A.A. 这个推导一下,找一下规律就可以了.答案是:ans=(n+1)2−1ans=\frac{(n+1)}{2}-1. B.B. 容易发现 ...

  10. Codeforces Round #645 (Div. 2) D - The Best Vacation 题解(二分+思维)

    题目链接 题目大意 一年有n个月,每个月有d[i]天,让你找出连续x天,使其日期的总和最大,可以跨年 题目思路 这里要发现一个性质:即连续的x天一定满足最后一天在月份的结尾,结论是显然的. 然后用两个 ...

最新文章

  1. Oracle 存储过程 无法编译 解决方法(转载)
  2. linux根据服务用YUM查询是由那些软件包安装
  3. 路由器命令大全手册教程 4
  4. SpringBoot+MyBatisPlus+DataTables实现退货管理的添加和编辑时控制checkbox的回显选中
  5. 内存溢出与内存泄漏区别
  6. 【HDU - 6662】Acesrc and Travel(树形dp,博弈dp)
  7. python 编程服务_Python编写Windows Service服务程序
  8. Web Service概念
  9. python实现顺序查找和哈希查找算法
  10. inline在C99以及Gcc中的处理方式[转]---很好的一篇总结
  11. 傲腾服务器系统,服务器装傲腾内存
  12. 【实践案例分享】阿里文娱智能营销增益模型 ( Uplift Model ) 技术实践
  13. 【前端性能】浅谈域名发散与域名收敛
  14. 编辑word文档过程中输入法无法正常使用
  15. 图像信息处理:bmp文件、颜色空间转化、灰度图
  16. Speedoffice(excel)如何加粗边框线条
  17. 基于javaweb的校园外卖点餐系统(java+ssm+jsp+mysql)
  18. 转【@入口@】伏草惟存,文章精选系列导航
  19. 读《game engine architecture》有感
  20. linux页游一键端,页游一键端是什么意思

热门文章

  1. 计算机网络配置——静态路由的配置
  2. 面试官常问的 web前端 问题(一)
  3. 昆明理工大学计算机考研资料汇总
  4. SQL注入入侵动网站(MSSQL)
  5. MPQ 文件系统完成
  6. @media用法解释
  7. 气不足则胖,血不足则瘦
  8. Arch LinuxLinux引导教程 2021.7.22
  9. 对话DeepMind创始人:建立通用人工智能
  10. ZZULIOJ 1196: 数星星(二)(结构体专题)