# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334279 | limabeans | Schools (IZhO13_school) | C++17 | 137 ms | 19548 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
int n, m, s;
vector<array<ll,3>> a;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m>>s;
a.resize(n);
for (int i=0; i<n; i++) {
cin>>a[i][0]>>a[i][1];
}
sort(a.rbegin(),a.rend());
for (int i=0; i<n; i++) {
a[i][2]=i;
}
vector<bool> used(n, false);
priority_queue<pair<ll,int>> pq;
ll sum = 0;
for (int i=0; i<m; i++) {
sum += a[i][0];
used[a[i][2]] = true;
pq.push({a[i][1]-a[i][0],a[i][2]});
}
auto b = a;
sort(b.begin(),b.end(),[&](array<ll,3> x, array<ll,3> y) {
return x[1]<y[1];
});
reverse(b.begin(),b.end());
int p1=0;
int p2=0;
for (int z=0; z<s; z++) {
while (p1<n && used[a[p1][2]]) p1++;
while (p2<n && used[b[p2][2]]) p2++;
auto cur = pq.top();
ll gain = cur.first;
if (gain+a[p1][0]>b[p2][1]) {
pq.pop();
sum += gain+a[p1][0];
pq.push({a[p1][1]-a[p1][0],a[p1][2]});
used[a[p1][2]]=true;
used[b[p2][2]]=true;
} else {
sum += b[p2][1];
used[b[p2][2]]=true;
}
}
cout<<sum<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |