Submission #879806

#TimeUsernameProblemLanguageResultExecution timeMemory
879806TAhmed33Akcija (COCI21_akcija)C++98
90 / 110
1697 ms524288 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 25; typedef long long ll; int n; pair <ll, ll> a[MAXN]; vector <pair <ll, ll>> dp[MAXN][MAXN]; bool comb (pair <ll, ll> &a, pair <ll, ll> &b) { return a.first == b.first ? a.second < b.second : a.first > b.first; } int main () { cin >> n; int k; cin >> 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; }); for (int j = 0; j <= n + 1; j++) dp[n + 1][j].push_back({0, 0}); for (int i = n; i >= 1; i--) { for (int j = 0; j <= n; j++) { dp[i][j] = dp[i + 1][j]; if (j + 1 > a[i].second) continue; if (j + 1 <= a[i].second) { for (auto [x, y] : dp[i + 1][j + 1]) { dp[i][j].push_back({x + 1, y + a[i].first}); } } sort(dp[i][j].begin(), dp[i][j].end(), comb); while (dp[i][j].size() > k) dp[i][j].pop_back(); } for (int j = 0; j <= n; j++) dp[i + 1][j].clear(); } for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:20:27: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |                 for (auto [x, y] : dp[i + 1][j + 1]) {
      |                           ^
Main.cpp:25:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |             while (dp[i][j].size() > k) dp[i][j].pop_back();
      |                    ~~~~~~~~~~~~~~~~^~~
Main.cpp:29:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |     for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\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...