Test instructions: given n (1 <= n <= 2*10^5) dice, given the maximum number of times each dice can be thrown (the minimum number is always 1), given the number of points thrown by all the dice and a, it is not possible to throw a few points per dice.
Consider the maximum and minimum conditions and make the difference (see the code comment for details)
#include <cstdio>#include<cstring>#include<cctype>#include<cstdlib>#include<cmath>#include<iostream>#include<sstream>#include<iterator>#include<algorithm>#include<string>#include<vector>#include<Set>#include<map>#include<deque>#include<queue>#include<stack>#include<list>typedefLong Longll; typedef unsignedLong LongLlu; Const intMAXN = -+Ten; Const intMaxt =200000+Ten; Const intINF =0x7f7f7f7f; Const DoublePI = ACOs (-1.0); Const DoubleEPS = 1e-6; using namespacestd; intN; ll A[maxt], A; intMain () {scanf ("%d%i64d", &n, &A); ll Allsum=0;//the total maximum value of all dice Max added up for(inti =0; I < n; ++i) {scanf ("%i64d", A +i); Allsum+=A[i]; } for(inti =0; I < n; ++i) {ll down= Max (1ll, A-(allsum-a[i]));//Dice minimum = required and-Other dice have all the maximum valuesll up = min (A[i], A-(N-1));//Dice max = required and-all other dice minimum value if(i) printf (" "); printf ("%i64d", A[i]-(Up-down +1));//The number that cannot occur = The number that can be represented in total-the number that is already able to represent } return 0; }
Codeforces 534c-polycarpus ' Dice (IDEA)