답안 #146916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146916 2019-08-26T15:03:35 Z bortoz Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
3 ms 376 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> V(N);
  set<int> L;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    V[i] = a - b;
    if (V[i] > 0) {
      L.insert(i);
    }
  }
  ll res = 0;
  for (int i = 0; i < N; i++) {
    while (V[i] < 0) {
      auto itR = L.lower_bound(i);
      if (itR == L.end()) {
        itR--;
      }
      auto itL = itR;
      if (itL != L.begin()) {
        itL--;
      }
      auto it = abs(i - *itL) < abs(i - *itR) ? itL : itR;
      int m = min(-V[i], V[*it]);
      res += 1ll * m * abs(i - *it);
      V[i] += m;
      V[*it] -= m;
      if (V[*it] == 0) {
        L.erase(it);
      }
    }
  }
  cout << res << endl;

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct