이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool compare(pair<ll, ll> a, pair<ll, ll> b) {
return a.first+a.second < b.first+b.second;
}
int main() {
int n;
cin >> n;
vector<pair<ll, ll>> gyms(n);
for (int i = 0; i < n; i++) {
cin >> gyms[i].first;
}
for (int i = 0; i < n; i++) {
cin >> gyms[i].second;
}
sort(gyms.begin(), gyms.end(), compare);
ll level = 0;
ll ans = 0;
priority_queue<ll> pq;
for (int i = 0; i < n; i++) {
if (level <= gyms[i].second) {
//cout << i << ' ' << level << ' ' << gyms[i].first << '\n';
level += gyms[i].first;
pq.push(gyms[i].first);
ans++;
}
else {
ll x = pq.top();
pq.pop();
if (level-x <= gyms[i].second && gyms[i].first < x) {
pq.push(gyms[i].first);
level -= x;
level += gyms[i].first;
}
else {
pq.push(x);
}
}
}
cout << ans << '\n';
return 0;
}
# | 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... |