Submission #503379

#TimeUsernameProblemLanguageResultExecution timeMemory
503379lukameladzeSchools (IZhO13_school)C++14
75 / 100
2071 ms19752 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back #define int long long #define pii pair <int, int> using namespace std; const int N = 3e5 + 5; int n,m,k,a[N],b[N],sum,num,ans,pr[N],sf[N]; multiset <int> ms; multiset <int> :: iterator it; vector <pii> v; main() { std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m>>k; for (int i = 1; i <= n; i++) { cin>>a[i]>>b[i]; v.pb({a[i] - b[i], i}); } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); for (int i = 0; i < v.size(); i++) { num = a[v[i].s]; if (ms.size() < m) { ms.insert(num); sum += num; } else { it = ms.begin(); if (*it < num) { sum -= *it; ms.erase(it); sum += num; ms.insert(num); } } pr[i] = sum; } sum = 0; ms.clear(); for (int i = (int)v.size() - 1; i >= 0; i--) { num = b[v[i].s]; if (ms.size() < k) { ms.insert(num); sum += num; } else { it = ms.begin(); if (*it < num) { sum -= *it; ms.erase(it); sum += num; ms.insert(num); } } sf[i] = sum; } for (int i = m; i <= n - k; i++) { ans = max(ans, pr[i] + sf[i + 1]); } cout<<ans<<endl; }

Compilation message (stderr)

school.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main() {
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:21:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
school.cpp:23:23: 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]
   23 |         if (ms.size() < m) {
      |             ~~~~~~~~~~^~~
school.cpp:40:23: 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]
   40 |         if (ms.size() < k) {
      |             ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...