还是比较好想到的..设第一个数为x,那么以后的所有数都能用x和M表示出来。

  然后再根据非递减的限制条件得出x的取值范围。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #define ll long long
 5 using namespace std;
 6 const int maxn=5002333;
 7 int i,j,k,n,m;
 8  
 9 int ra;char rx;
10 inline int read(){
11     rx=getchar(),ra=0;
12     while(rx<'0'||rx>'9')rx=getchar();
13     while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra;
14 }
15 int main(){
16     ll sm,mx,mn;int pre,now;
17     n=read();pre=mn=sm=read(),mx=-(1<<30);
18     for(i=2;i<=n&&mx<=mn;i++){
19         now=read();
20         if(i&1)sm+=now-pre,mn=min(mn,sm);else sm+=pre-now,mx=max(mx,sm);
21 //      printf("  %lld  %lld    sm:%lld\n",mx,mn,sm);
22         pre=now;
23     }
24     if(mx>mn)puts("0");else printf("%lld\n",mn-mx+1);
25 }
View Code

相关文章:

  • 2022-03-09
  • 2022-12-23
  • 2021-12-06
  • 2021-12-04
  • 2021-05-23
  • 2021-12-06
  • 2021-07-27
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
相关资源
相似解决方案