Submission #936035

#TimeUsernameProblemLanguageResultExecution timeMemory
93603512345678Schools (IZhO13_school)C++17
95 / 100
2059 ms18608 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=3e5+5; int n, m, s; ll dp[2][nx],res; vector<int> a, b; struct value { int a, b; bool operator< (const value &o) const {return (a-b)<(o.a-o.b);} } d[nx]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>s; for (int i=1; i<=n; i++) cin>>d[i].a>>d[i].b; sort(d+1, d+n+1); //for (int i=1; i<=n; i++) cout<<"value "<<i<<' '<<d[i].a<<' '<<d[i].b<<'\n'; for (int i=1; i<=n; i++) a.push_back(d[i].a), b.push_back(d[i].b); multiset<int> ms; ll sm=0; for (int i=n-1; i>=0; i--) { if (ms.size()<m) ms.insert(a[i]), sm+=a[i]; else if (a[i]>*ms.begin()) sm+=a[i]-*ms.begin(), ms.erase(ms.begin()), ms.insert(a[i]); dp[0][i]=(ms.size()>=m)?sm:-1e18; } ms.clear(); sm=0; for (int i=0; i<n; i++) { if (ms.size()<s) ms.insert(b[i]), sm+=b[i]; else if (b[i]>*ms.begin()) sm+=b[i]-*ms.begin(), ms.erase(ms.begin()), ms.insert(b[i]); dp[1][i]=(ms.size()>=s)?sm:-1e18; } //for (int i=0; i<n; i++) cout<<i<<' '<<dp[0][i]<<' '<<dp[1][i]<<'\n'; if (s==0) return cout<<dp[0][0], 0; if (m==0) return cout<<dp[1][n-1], 0; for (int i=0; i<n-1; i++) res=max(res, dp[0][i+1]+dp[1][i]); cout<<res; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:30:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |         if (ms.size()<m) ms.insert(a[i]), sm+=a[i];
      |             ~~~~~~~~~^~
school.cpp:32:28: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         dp[0][i]=(ms.size()>=m)?sm:-1e18;
      |                   ~~~~~~~~~^~~
school.cpp:38:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if (ms.size()<s) ms.insert(b[i]), sm+=b[i];
      |             ~~~~~~~~~^~
school.cpp:40:28: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         dp[1][i]=(ms.size()>=s)?sm:-1e18;
      |                   ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...