Test instructions
Give some numbers, require that each number is not the same need to add a few
Ideas:
First sort, then increment each, and finally seek the sum of difference
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack > #include <queue> #include <map> #include <set> #include <vector> #include <math.h># Include <bitset> #include <list> #include <algorithm> #include <climits>using namespace std;# Define Lson 2*i#define Rson 2*i+1#define LS l,mid,lson#define RS mid+1,r,rson#define Up (i,x,y) for (i=x;i<=y;i++) # Define down (i,x,y) for (i=x;i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define GCD (A, B) __ GCD (A, b) #define LL long long#define N 5000005#define INF 0x3f3f3f3f#define EXP 1e-8#define lowbit (x) (x&-x) const int M OD = 1e9+7; #define LL __int64int N,a[3005];int main () {int i,j,ans; while (~SCANF ("%d", &n)) {ans = 0; int sum1 = 0,sum2 = 0; for (i = 1; i<=n; i++) {scanf ("%d", &a[i]); Sum1+=a[i]; } sort (a+1,a+1+n); sum2 = a[1]; for (i = 2; i<=n; i++) {if (a[i] = = a[i-1]) a[i]++; else if (a[i]<a[i-1]) a[i] + = (a[i-1]-a[i]) +1; Sum2+=a[i]; } printf ("%d\n", SUM2-SUM1); } return 0;}
Codeforces546b:soldier and Badges