Submission #879442

#TimeUsernameProblemLanguageResultExecution timeMemory
879442TAhmed33Akcija (COCI21_akcija)C++98
0 / 110
1872 ms524288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector <pair <ll, ll>> subs; int n; ll w[2001], dd[2001]; vector <int> cur; void recurse (int pos, int sze, ll cost) { if (pos == n) { if (cur.empty()) return; vector <int> s = cur; sort(s.begin(), s.end(), [&] (int a, int b) { return dd[a] < dd[b]; }); bool flag = 1; for (int i = 0; i < sze; i++) { flag &= i < dd[s[i]]; } if (!flag) return; subs.push_back({sze, cost}); return; } recurse(pos + 1, sze, cost); cur.push_back(pos); recurse(pos + 1, sze + 1, cost + w[pos]); cur.pop_back(); } int main () { cin >> n; int k; cin >> k; for (int i = 0; i < n; i++) cin >> w[i] >> dd[i]; recurse(0, 0, 0); sort(subs.begin(), subs.end(), [] (pair <ll, ll> &a, pair <ll, ll> &b) { return a.first == b.first ? a.second < b.second : a.first > b.first; }); for (int i = 0; i < k; i++) { cout << subs[i].first << " " << subs[i].second << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...