?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
76131257 |
Contestant: mouse_wireless |
1334C - 23 | C++17 (GCC 7-32) | Accepted | 311 ms | 4712 KB | 2020-04-10 18:05:02 | 2020-04-11 10:18:37 |
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define mp make_pair #define CHECK(x) if(!(x)) return false; #define CHECKRET(x, y) if(!(x)) return (y); #define SKIP(x) if((x)) continue; typedef pair<int, int> pii; const int MAXN = 3 * 100010; LL a[MAXN], b[MAXN]; int main() { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); for (int i = 0; i < N; ++i) scanf("%I64d%I64d", &a[i], &b[i]); LL best = LLONG_MAX; LL cst = 0; for (int i = 0; i < N; ++i) { int iminus1 = (i - 1 + N) % N; LL what = max(a[i] - b[iminus1], 0LL); cst += what; best = min(best, a[i] - what); } cst += best; printf("%I64d\n", cst); } return 0; }
?
?
?
?