| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1356411 | 4o2a | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 174 ms | 27832 KiB |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define _F "what"
using namespace std;
typedef long long ll;
void solve()
{
int n; cin>>n;
vector<ll> x(n+1);
ll A = 0, B = 0, res = 0;
for (int i = 1; i <= n; ++i)
{
int a, b; cin>>a>>b;
A += a, B += b;
x[i] = A - B;
}
for (int i = 1; i < n; ++i)
{
if (x[i] < 0)
{
res += -x[i];
x[i] = 0;
}
if (x[i] > x[n])
{
res += x[i] - x[n];
x[i] = x[n];
}
}
multiset<ll> S; S.insert(x[1]);
for (int i = 2; i <= n; ++i)
{
S.insert(x[i]);
if (*prev(S.end()) > x[i])
{
res += *prev(S.end()) - x[i];
S.insert(x[i]);
S.erase(prev(S.end()));
}
}
cout<<res;
}
int main()
{
if (fopen(_F".INP", "r"))
{
freopen(_F".INP", "r", stdin);
freopen(_F".OUT", "w", stdout);
}
else if (fopen("test.inp", "r"))
{
freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
int Test = 1; //cin>>Test;
while (Test--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
