Submission #819175

#TimeUsernameProblemLanguageResultExecution timeMemory
819175cig32Akcija (COCI21_akcija)C++17
90 / 110
5049 ms57812 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define double long double const int MAXN = 1e5 + 10; const int MOD = 1e9 + 7; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } bool cmp(pair<int, int> x, pair<int, int> y) { return x.second < y.second; } void solve(int tc) { int n, k; cin >> n >> k; pair<int, int> p[n+1]; for(int i=1; i<=n; i++) cin >> p[i].first >> p[i].second; sort(p+1, p+1+n, cmp); int dp[2][n+1][k+1]; for(int i=1; i<=n; i++) { for(int j=1; j<=k; j++) { dp[0][i][j] = 1e18; } } dp[0][0][1] = 0; for(int i=2; i<=k; i++) dp[0][0][i] = 1e18; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> sol; sol.push({0, 0}); for(int i=1; i<=n; i++) { for(int j=0; j<i; j++) { for(int l=1; l<=k; l++) { dp[i&1][j][l] = 1e18; } } int opt[k+1]; for(int j=1; j<=k; j++) opt[j] = 1e18; for(int j=0; j<i; j++) { int res[k+1]; int p1 = 1, p2 = 1; for(int l=1; l<=k; l++) { if(dp[(i-1)&1][j][p1] < opt[p2]) { res[l] = dp[(i-1)&1][j][p1++]; } else { res[l] = opt[p2++]; } } for(int l=1; l<=k; l++) { opt[l] = res[l]; } } for(int j=i; j<=n; j++) { if(p[j].second >= i) { for(int l=1; l<=k; l++) dp[i&1][j][l] = opt[l] + p[j].first; } else { for(int l=1; l<=k; l++) dp[i&1][j][l] = 1e18; } int res[k+1]; int p1 = 1, p2 = 1; for(int l=1; l<=k; l++) { if(dp[(i-1)&1][j][p1] < opt[p2]) { res[l] = dp[(i-1)&1][j][p1++]; } else { res[l] = opt[p2++]; } } for(int l=1; l<=k; l++) { opt[l] = res[l]; } } for(int j=i; j<=n; j++) { for(int l=1; l<=k; l++) { if(dp[i&1][j][l] <= 1e13) sol.push({i, -dp[i&1][j][l]}); if(sol.size() > k) sol.pop(); } } } while(sol.size() > k) sol.pop(); stack<pair<int, int> > stk; for(int i=0; i<k; i++) { stk.push({sol.top().first, -sol.top().second}); sol.pop(); } for(int i=0; i<k; i++) { cout << stk.top().first << ' ' << stk.top().second << '\n'; stk.pop(); } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); } // 勿忘初衷

Compilation message (stderr)

Main.cpp: In function 'void solve(long long int)':
Main.cpp:90:23: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   90 |         if(sol.size() > k) sol.pop();
      |            ~~~~~~~~~~~^~~
Main.cpp:94:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   94 |   while(sol.size() > k) sol.pop();
      |         ~~~~~~~~~~~^~~
#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...