C. Polycarpus' Dice

在每个位置讨论一下最大值最小值的取值范围就行

 1 #include<cstdio>
 2 #include<iostream>
 3 #define maxn 200003
 4 using namespace std;
 5 typedef long long LL;
 6 LL a[maxn],b[maxn];
 7 
 8 int main()
 9 {
10     LL n,s;
11     while(scanf("%I64d %I64d",&n,&s)!=EOF)
12     {
13         LL sum=0;
14        // memset(b,0,sizeof(b));
15         for(int i=1; i<=n; i++)
16         {
17             scanf("%I64d",&a[i]);
18             sum+=a[i];
19         }
20         if(n==1)
21             printf("%I64d
",a[1]-1);
22         else
23         {
24             for(int i=1; i<=n; i++)
25             {
26                 LL tem=s-(sum-a[i]);
27                 if(tem>1)
28                     b[i]=tem-1;
29                 else
30                     b[i]=0;
31                 if(s-(n-1)<=a[i])
32                     b[i]+=a[i]-(s-(n-1));
33 
34             }
35             for(int i=1;i<=n;i++)
36             {
37                 if(i!=1)
38                     printf(" ");
39                 printf("%I64d",b[i]);
40             }
41          printf("
");
42         }
43     }
44     return 0;
45 }

注意用long long

原文地址:https://www.cnblogs.com/tsw123/p/4430132.html