| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 331337 | Nson | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 18 ms | 748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(*prev(s.end()) > 0) return true;
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();
printf("%lld\n", d * m + b);
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
