标签:code problems while for else ems problem std http
#include <cstdio>
int a[300010], b[300010];
int main() {
int n, m, ans = 0;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
int l = 0, r = m;
while(l < r) {
int mid = (l + r) / 2, flag = 0;
b[0] = a[0];
if(a[0] + mid >= m) b[0] = 0;
for(int i = 1; i < n; i++) {
if(a[i] >= b[i-1]) {
b[i] = a[i];
if(a[i] + mid >= m && (a[i] + mid) % m >= b[i-1]) b[i] = b[i-1];
}
else if(a[i] + mid >= b[i-1]) b[i] = b[i-1];
else {
flag = 1;
break;
}
}
if(flag) l = mid + 1;
else ans = mid, r = mid;
}
printf("%d\n", ans);
return 0;
}
cf 1169 C Increasing by Modulo
标签:code problems while for else ems problem std http
原文地址:https://www.cnblogs.com/fanshhh/p/11380589.html