Submission #566065

# Submission time Handle Problem Language Result Execution time Memory
566065 2022-05-21T17:45:02 Z lorenzoferrari Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
4 ms 468 KB
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

struct SlopeTrick {
  LL inc = 0;
  multiset<LL> s;
  void insert(LL x){ s.insert(x - inc); }
  void pop(){ s.erase(s.begin()); }
  void increase(LL v) { inc += v; }
  LL getmin() {
    return *s.begin() + inc;
  }
  multiset<int> get() {
    multiset<int> ans;
    for (LL x : s) ans.insert(x + inc);
    return ans;
  }
};

int main() {
#ifdef LORENZO
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n; cin >> n;
  SlopeTrick st;
  LL sum = 0;
  LL ans = 0;
  for (int i = 0, a, b; i < n; ++i) {
    cin >> a >> b;
    int v = b - a;
    sum += v;
    st.increase(v);
    st.insert(v);
    st.insert(v);
    ans += v - st.getmin();
    st.pop();
  }
  cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Incorrect 4 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Incorrect 4 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Incorrect 4 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Incorrect 4 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -