Submission #339494

#TimeUsernameProblemLanguageResultExecution timeMemory
339494tengiz05Schools (IZhO13_school)C++17
70 / 100
363 ms6304 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+5;
pair<int, int> a[N];
bool cmp(pair<int, int> A, pair<int, int> B){
  return A.first - A.second >= B.first - B.second;
}
int pr[N];
int sf[N];
int main(){
  int n, m, s;
  cin >> n >> m >> s;
  for(int i=1;i<=n;i++){
    cin >> a[i].first >> a[i].second;
  }
  sort(a+1, a+n+1, cmp);
  priority_queue<int, vector<int>, greater<int>> q;
  int sum = 0;
  for(int i=1;i<=n;i++){
    q.push(a[i].first);
    sum += a[i].first;
    if(q.size() > m){
      sum -= q.top();q.pop();
    }pr[i] = sum;
  }
  while(q.size())q.pop();
  sum = 0;
  for(int i=n;i>=1;i--){
    q.push(a[i].second);
    sum += a[i].second;
    if(q.size() > s){
      sum -= q.top();q.pop();
    }sf[i] = sum;
  }
  pr[0] = pr[1];
  sf[n+1] = sf[n];
  int ans = 0;
  for(int i=0;i<n;i++)ans = max(ans, pr[i] + sf[i+1]);
  cout << ans << '\n';
  return 0;
}

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:22:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     if(q.size() > m){
      |        ~~~~~~~~~^~~
school.cpp:31:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     if(q.size() > s){
      |        ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...