# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
676391 | vjudge1 | 학교 설립 (IZhO13_school) | C++17 | 114 ms | 9112 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define oo 1e18
#define ii pair<int,int>
using namespace std;
int id[1000010],a[1000010],b[1000010],x,y,n;
long long f[1000010],g[1000010];
priority_queue<int,vector<int>,greater<int> >pq;
bool cmp(int i,int j)
{
return a[i] - b[i] < a[j] - b[j];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("invest.inp","r",stdin);
//freopen("invest.out","w",stdout);
cin >> n >> x >> y;
for (int i = 1;i <= n;i++)
{
cin >> a[i] >> b[i];
}
for (int i = 1;i <= n;i++)
{
id[i] = i;
}
sort(id + 1,id + n + 1,cmp);
for (int i = 1;i <= n;i++)
{
f[i] = f[i - 1] + b[id[i]];
pq.push(b[id[i]]);
if (pq.size() > y)
{
f[i] -= pq.top();
pq.pop();
}
}
while (pq.size() > 0)
{
pq.pop();
}
for (int i = n;i >= 1;i--)
{
g[i] = g[i + 1] + a[id[i]];
pq.push(a[id[i]]);
if (pq.size() > x)
{
g[i] -= pq.top();
pq.pop();
}
}
long long res = 0;
for (int i = 1;i <= n;i++)
{
if ((i >= y) && (n - i >= x))
{
res = max(res,f[i] + g[i + 1]);
}
}
cout << res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |