Submission #879943

#TimeUsernameProblemLanguageResultExecution timeMemory
879943TAhmed33Akcija (COCI21_akcija)C++98
90 / 110
5064 ms41140 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") using namespace std; const int MAXN = 2e3 + 25; typedef long long ll; int n, k; pair <ll, ll> a[MAXN]; vector <ll> dp[2][MAXN]; vector <ll> merge (vector <ll> &a, vector <ll> &b, ll c) { vector <ll> ret; int p1 = 0, p2 = 0; while ((int)ret.size() < k && p1 < (int)a.size() && p2 < (int)b.size()) { if (a[p1] < b[p2] + c) { ret.push_back(a[p1++]); } else { ret.push_back(b[p2++] + c); } } while ((int)ret.size() < k && p1 < (int)a.size()) ret.push_back(a[p1++]); while ((int)ret.size() < k && p2 < (int)b.size()) ret.push_back(b[p2++] + c); return ret; } int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1, [] (pair <ll, ll> &x, pair <ll, ll> &y) { return x.second < y.second; }); dp[0][0].push_back(0); for (int i = 0, c = 0; i <= n - 1; i++, c ^= 1) { for (int j = 0; j <= n; j++) dp[c ^ 1][j] = dp[c][j]; for (int j = a[i + 1].second - 1; j >= 0; j--) { dp[c ^ 1][j + 1] = merge(dp[c ^ 1][j + 1], dp[c][j], a[i + 1].first); } /* int sum = 0; int bad = -1; for (int j = a[i + 1].second - 1; j >= 0; j--) { sum += dp[c ^ 1][j + 1].size(); if (sum >= k) { bad = j - 1; break; } } for (int j = bad; j >= 0; j--) { dp[c ^ 1][j].clear(); }*/ } for (int i = n; i >= 0; i--) { for (auto j : dp[n & 1][i]) { cout << i << " " << j << '\n'; k--; if (k == 0) break; } if (k == 0) break; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...