Submission #502026

#TimeUsernameProblemLanguageResultExecution timeMemory
502026AktanSchools (IZhO13_school)C++17
100 / 100
283 ms25496 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define int long long #define ft first #define sc second using namespace std; const int mod=1e9+7,INF=1e17,N=3e5+5; int pr[N],sf[N]; main(){ int n,m,k; cin >> n >> m >> k; vector<int> a(n),b(n); vector<pair<pair<int,int>,int>> v; for(int i=0;i<n;i++){ cin >> a[i] >> b[i]; v.push_back({{a[i]-b[i],a[i]},b[i]}); } sort(v.rbegin(),v.rend()); int sum=0; multiset<int> s; for(int i=0;i<n;i++){ sum+=v[i].ft.sc; s.insert(v[i].ft.sc); if(s.size()>m){ sum-=*s.begin(); s.erase(s.begin()); } pr[i]=sum; } s.clear(); sum=0; for(int i=n-1;i>=0;i--){ sum+=v[i].sc; s.insert(v[i].sc); if(s.size()>k){ sum-=*s.begin(); s.erase(s.begin()); } sf[i]=sum; } int ans=0; for(int i=0;i<n;i++){ ans=max(ans,pr[i]+sf[i+1]); } cout << ans; }

Compilation message (stderr)

school.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:27:14: 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]
   27 |   if(s.size()>m){
      |      ~~~~~~~~^~
school.cpp:38:14: 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]
   38 |   if(s.size()>k){
      |      ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...