Codeforces 1028E(模拟)

Codeforces 1028E
题意:给你一个环$b$,要你构造一个环$a$,满足$a_i \% a_{i + 1}=b_i$

设$max(b)=mks$,要找到一个数$i$使得$b_i=mks$并且$b_{i-1} < b_i$
然后让$a_i=b_i$,然后后面的就按照$a_i=b_{i+1}+b_i$来算。对于前面的约束也很清楚了,否则余数不对。
然后就是注意无解当且仅当所有数相同并且不是$0$。
然后还要对$0$作出特判。
1、所有数都是$0$,直接输出$n$个相同数即可
2、如果当前$b_i=0​$并且$a_i=mks​$,那么$a_i​$要乘$2​$,否则无法通过下面数据

5
0 0 0 100 0
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define ULL unsigned long long
#define db double

LL n, b[200000 + 5], a[200000 + 5], pos = 1, flag = true, mks;

void clean() {

}
int solve() {
    clean();
    for (LL i = 1; i <= n; i++) {
        scanf("%lld", &b[i]);
        if (b[pos] < b[i]) pos = i;
        if (i != 1 && b[i] != b[i - 1]) flag = false;
    }
    if (flag && b[1] > 0) return printf("NO\n"), 0;//
    mks = b[pos];
    for (LL i = 1; i <= n; i++) {
        LL now;
        if (i - 1 <= 0) now = n; else now = i - 1;
        if (b[i] != b[now] && b[i] == mks) {
            pos = i; break;
        }
    }
    a[pos] = b[pos];
    if (a[pos] == 0) {
        printf("YES\n");
        for (LL i = 1; i <= n; i++) printf("%lld ", 233ll);
        return 0;
    }//0
    LL cnt = 1;
    while (cnt <= n - 1) {
        LL now;
        if (pos - 1 <= 0) now = n; else now = pos - 1;
        a[now] = a[pos] + b[now];
        if (b[now] == 0 && a[now] == mks) a[now] *= 2ll;//0
        cnt++, pos = now;
    }
    printf("YES\n");
    for (LL i = 1; i <= n; i++) printf("%lld ", a[i]);
    return 0;
}
int main() {
    scanf("%lld", &n), solve();
    return 0;
}
------ 本文结束 ------