제출 #1091521

#제출 시각아이디문제언어결과실행 시간메모리
1091521vjudge1Potatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1039 ms10084 KiB
#include <cstdlib>
#include <iostream>
#include <vector>

int main() {
  std::cin.tie(NULL)->sync_with_stdio(false);

  int n;
  std::cin >> n;

  std::vector<int> diff(n);
  long long ans = 0;
  long long total = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    std::cin >> a >> b;
    total += a - b;
    diff[i] = total > 0 ? -1 : 1;
    ans += std::abs(total);
  }

  std::cerr << "a: " << ans << std::endl;
  std::cerr << "D:"; for (int x: diff) std::cerr << " " << x; std::cerr << std::endl;

  if (total == 1) {
    long long current = ans, total_diff = 0;
    while (!diff.empty()) {
      total_diff += diff.back();
      diff.pop_back();
      ans = std::min(ans, current + total_diff);
    }
  }

  std::cout << ans << std::endl;
  return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...