# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
331339 | 2020-11-28T03:45:41 Z | Nson | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 337 ms | 28652 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; scanf("%d", &n); multiset<ll> s; ll m = 0, b = 0; // s.insert(0); auto can_rem = [&]() { if(s.empty()) return false; if(m <= 0) return false; if(*prev(s.end()) < 0) return false; if((int)s.size() >= 2 and *prev(prev(s.end())) >= 0) return true; return false; }; auto smooth = [&]() { while(can_rem()) { m--; b += *prev(s.end()); s.erase(prev(s.end())); } }; ll d = 0; for(int i = 0; i < n; i++) { int aa, bb; scanf("%d %d", &aa, &bb); aa -= bb; d += aa; smooth(); if(d >= 0) { s.insert(d); s.insert(d); b -= d; m += 1; } else { m += 1; b -= d; } // while(!s.empty() and *s.begin() < 0) s.erase(s.begin()); } // smooth(); while(!s.empty() and *prev(s.end()) > d) { m--; b += *prev(s.end()); s.erase(prev(s.end())); } printf("%lld\n", d * m + b); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 20 ms | 748 KB | Output is correct |
5 | Correct | 68 ms | 3052 KB | Output is correct |
6 | Correct | 186 ms | 15084 KB | Output is correct |
7 | Correct | 133 ms | 7020 KB | Output is correct |
8 | Correct | 303 ms | 28652 KB | Output is correct |
9 | Correct | 152 ms | 7020 KB | Output is correct |
10 | Correct | 322 ms | 25836 KB | Output is correct |
11 | Correct | 337 ms | 25708 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 20 ms | 748 KB | Output is correct |
5 | Correct | 68 ms | 3052 KB | Output is correct |
6 | Correct | 186 ms | 15084 KB | Output is correct |
7 | Correct | 133 ms | 7020 KB | Output is correct |
8 | Correct | 303 ms | 28652 KB | Output is correct |
9 | Correct | 152 ms | 7020 KB | Output is correct |
10 | Correct | 322 ms | 25836 KB | Output is correct |
11 | Correct | 337 ms | 25708 KB | Output is correct |
12 | Incorrect | 74 ms | 5736 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Incorrect | 1 ms | 364 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Incorrect | 1 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Incorrect | 1 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |