제출 #1349961

#제출 시각아이디문제언어결과실행 시간메모리
1349961avighnaAnts and Sugar (JOI22_sugar)C++20
6 / 100
4091 ms2528 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int q, l;
  cin >> q >> l;

  map<int, int64_t> ants, sugar;

  auto solve = [&]() {
    auto _ants = ants, _sugar = sugar;
    int64_t ans = 0;
    auto it_ant = ants.begin(), it_sugar = sugar.begin();
    while (it_ant != ants.end() && it_sugar != sugar.end()) {
      if (it_ant->second == 0) {
        it_ant++;
        continue;
      }
      if (it_sugar->second == 0) {
        it_sugar++;
        continue;
      }
      // ant before sugar
      if (it_sugar->first - it_ant->first > l) {
        it_ant++;
        continue;
      }
      // sugar before ant
      if (it_ant->first - it_sugar->first > l) {
        it_sugar++;
        continue;
      }
      // both of them are not nil and in reach
      int64_t cur = min(it_ant->second, it_sugar->second);
      it_ant->second -= cur, it_sugar->second -= cur, ans += cur;
    }
    ants = _ants, sugar = _sugar;
    return ans;
  };

  while (q--) {
    int t, x, a;
    cin >> t >> x >> a;
    if (t == 1) {
      ants[x] += a;
    } else {
      sugar[x] += a;
    }
    cout << solve() << '\n';
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...