提交时间:2021-05-08 20:12:12
运行 ID: 19160
#include<bits/stdc++.h> using namespace std; typedef long long p; int n, r; int a[200],ool[105],oor[105],ans; int main(){ cin>>n>>r; a[1]=r%10; for(int i=2;i<=n;i++){ r=(r*6807%201701+2831)%201701; a[i]=r%10; } for(int i=1;i<=n;i++){ ool[i]=max(ool[i-1],a[i]); } for (int i=n;i>=1;i--){ oor[i]=max(oor[i+1],a[i]); } for(int i=2;i<n;i++){ int t=min(ool[i-1],oor[i+1]); if(a[i]>=t) continue; ans+=t-a[i]; } cout<<ans<<endl; return 0; }