提交时间:2021-05-02 22:29:48
运行 ID: 18961
#include <cstdio> #include <cstring> #include <cmath> #include <cctype> #include <iostream> #include <algorithm> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <queue> typedef long long LL; using namespace std; int n, r; int a[105], lmax[105], rmax[105]; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); scanf("%d %d", &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++){ lmax[i] = max(lmax[i - 1], a[i]); } for (int i = n; i >= 1; i--){ rmax[i] = max(rmax[i + 1], a[i]); } int ans = 0; for (int i = 2; i < n; i++){ int t = min(lmax[i - 1], rmax[i + 1]); if(a[i] >= t) continue; ans += t - a[i]; } printf("%d\n", ans); return 0; }