用差分求一下后缀和可以完成。 AC code: #include<bits/stdc++.h>usingnamespacestd; typedeflonglongll;constll N=2E5+7; ll arr[N];intmain() { ll n,k; cin>>n>>k; ll x; ll c=0;for(ll i=1;i<=n;i++){ cin>>x; c=max(x,c); arr[x]++; }for(ll i=c;i>=1;i--){ ...
Make It Equal(思维+细心) C. Make It Equal time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is a toy building consisting of nn towers. Each tower consists of Educational Codeforces Round 52 (Rated for Div. 2) 有一组是三...
LL n,k;inta[200050];boolcmp(intx,inty){returnx>y; }intminn=2147483647,maxn=0;intb[200050];intmain(){scanf("%lld%lld",&n,&k);for(inti(1);i<=n;i++)scanf("%d",&a[i]),minn=min(minn,a[i]),maxn=max(maxn,a[i]);if(n==1){ cout<<0;return0; }for(inti(1);i<=n...
Codeforces 1154B Make Them Equal 题目链接:http://codeforces.com/problemset/problem/1154/B 题意:给定数组,可以给任意的的元素加上D 或者 减去D,如果能 使数组元素都相等,输出最小的D,不能输出-1。 思路:若要相等,唯有种类数小于3的才可以。 AC代码: 1#include<bits/stdc++.h>2usingnamespacestd;3int...
CodeForces 1188D Make Equal DP dp[bit][j]填完了bit位之后,产生进位的状态是j,所需的最小花费。 若j以二进制(0010010..)的第i位表示第i个数是否发生进位,则j的状态有1<<n个; 假设结束时所有数均为X,考虑每个数第bit位是否有进位,即在模 1 << (bit + 1) 下 a[i] >= X是否满足。 由此...
For each test case, output one integer — the minimum number of burles that will have to be spent to make all the elements of the array equal. It can be shown that this can always be done. Input The first line contains a single integer tt (1≤t≤1041≤t≤104)— the number of inp...
Make k Equal 链接https://codeforces.com/contest/1328/problem/F 题意 操作一:使最小的数加一 操作二:使最大的数减一 求最小操作数使序列中有 k k k 个相同的数 思路 排序后,枚举每个不同的数 操作只有三种 Case: 只操作比当前小的数 只操作比当前大的数 操作一部分比当前小的数,操作一部分比...
It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There arenpeople, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutationp...
Codeforces Round 673 (Div. 1) B. Make Them Equal bhdtr Warframe高手 3 人赞同了该文章 Problem - B - Codeforcescodeforces.com/contest/1416/problem/B 好巧妙的做法。 题意: 给定一个长度为 n 的数组,第 i 个数的大小为 a[i],每次操作你可以选定 i, j, x 使得,a[i] = a[i] - i ...
I think this was a problem in a codeforces or topcoder, but I cannot remember where. For example, if N = 5 and we have Array = [6, 1, 1, 1, 1], you can make them all equal to 2 in just four operations. Clearly, they all need to become equal to Sum/N, but the hard par...