이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
struct Gym {
ll L, X;
};
bool operator<(const Gym &a, const Gym &b) {
if (a.X != b.X) {
return a.X < b.X;
}
return a.L < b.L;
}
int main() {
ll n;
std::cin >> n;
std::vector<Gym> a(n);
for (ll i = 0; i < n; ++ i) {
std::cin >> a[i].X;
}
for (ll i = 0; i < n; ++ i) {
std::cin >> a[i].L;
}
std::sort(a.begin(), a.end(), [](const Gym &i, const Gym &j) {
return std::min(i.L, j.L - i.X) > std::min(j.L, i.L - j.X);
});
std::multiset<Gym> dp;
ll level = 0;
for (ll i = 0; i < n; ++ i) {
if (dp.empty() || level <= a[i].L) {
dp.insert(a[i]);
level += a[i].X;
} else if (level - dp.rbegin()->X <= a[i].L && dp.rbegin()->X > a[i].X) {
level -= dp.rbegin()->X;
dp.erase(--dp.end());
dp.insert(a[i]);
level += a[i].X;
}
}
std::cout << dp.size() << "\n";
}
# | 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... |