codeforces C. Omkar and Waterslide

codeforces C. Omkar and Waterslide
文章图片

题目 题意: 给你一个序列,你有个操作,可以将连续不递减的区间里面的值都增加 1 1 1,问最后要使这个序列变成不递减的序列要进行多少次这样的操作。
思路: 【codeforces C. Omkar and Waterslide】如果出现递减的情况,也就是 a i < a i ? 1 a_iai?

#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector veci; typedef vector vecl; typedef pair pii; typedef pair pll; template inline void read(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return ; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1:1; ret = (c == '-') ? 0:(c - '0'); while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return ; } inline void outi(int x) {if (x > 9) outi(x / 10); putchar(x % 10 + '0'); } inline void outl(ll x) {if (x > 9) outl(x / 10); putchar(x % 10 + '0'); } const int maxn = 2e5 + 10; int a[maxn]; int main() { int t; read(t); while (t--) { int n; read(n); for (int i = 1; i <= n; i++) read(a[i]); ll ans = 0; int Max = 0; for (int i = 2; i <= n; i++) { if (a[i] < a[i - 1]) ans += a[i - 1] - a[i]; } printf("%lld\n", ans); } return 0; }

    推荐阅读