Codeforces546b:soldier and Badges

Source: Internet
Author: User

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

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.