Submission #902618

#TimeUsernameProblemLanguageResultExecution timeMemory
902618SalihSahinAkcija (COCI21_akcija)C++17
90 / 110
5010 ms18756 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define mp make_pair using namespace std; const int mod = 1e9 + 7; const int inf = 1e17*2; const int N = 2e5 + 5; int32_t main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n, k; cin>>n>>k; multiset<int> best[n+2]; best[0].insert(0); vector<pair<int, int> > a(n); for(int i = 0; i < n; i++){ cin>>a[i].second>>a[i].first; } sort(a.begin(), a.end()); for(int i = 0; i < n; i++){ for(int j = a[i].first-1; j >= 0; j--){ for(auto itr: best[j]){ best[j+1].insert(a[i].second + itr); } while(best[j+1].size() > k){ auto k = best[j+1].end(); k--; best[j+1].erase(k); } } } vector<pair<int, int> > ans; for(int i = n; i >= 0; i--){ for(auto itr: best[i]){ ans.pb(mp(i, itr)); } if(ans.size() > k) break; } for(int i = 0; i < k; i++){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:29:36: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   29 |             while(best[j+1].size() > k){
      |                   ~~~~~~~~~~~~~~~~~^~~
Main.cpp:42:23: 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 'long long int' [-Wsign-compare]
   42 |         if(ans.size() > k) 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...