Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# 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
→ Source
#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;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details