This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B>
string to_string(pair<A, B>);
string to_string(string S) {
return '"' + S + '"';
}
string to_string(const char* c) {
return to_string(string(c));
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template<size_t T>
string to_string(bitset<T> bs) {
return bs.to_string();
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < int(v.size()); ++i) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(v[i]);
}
return res + "}";
}
template<typename T>
string to_string(T v) {
string res = "{";
for (auto e : v) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(e);
}
return res + "}";
}
template<typename T>
string to_string(priority_queue<T> pq) {
vector<T> a;
while (!pq.empty()) {
a.push_back(pq.top());
pq.pop();
}
return to_string(a);
}
template<typename A, typename B>
string to_string(pair<A, B> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename H, typename... T>
void debug_out(H head, T... tail) {
cerr << " " << to_string(head);
debug_out(tail...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(37)
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> X(N), L(N);
for (int i = 0; i < N; ++i) {
cin >> X[i];
}
for (int i = 0; i < N; ++i) {
cin >> L[i];
}
vector<int> S(N);
for (int i = 0; i < N; ++i) {
S[i] = X[i] + L[i];
}
vector<int> ord(N);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) {
return S[x] < S[y];
});
priority_queue<int> pq;
long long last = 0;
for (auto i : ord) {
pq.push(X[i]);
last += X[i];
if (last > S[i]) {
last -= pq.top();
pq.pop();
}
}
cout << int(pq.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... |