Submission #886520

#TimeUsernameProblemLanguageResultExecution timeMemory
886520vjudge1Gym Badges (NOI22_gymbadges)C++17
100 / 100
152 ms18400 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...