Submission #339497

#TimeUsernameProblemLanguageResultExecution timeMemory
339497tengiz05Schools (IZhO13_school)C++17
95 / 100
375 ms10720 KiB
#include <bits/stdc++.h>
#define int long long
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];
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:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      |      ^
school.cpp: In function 'int main()':
school.cpp:23:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |     if(q.size() > m){
      |        ~~~~~~~~~^~~
school.cpp:32:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   32 |     if(q.size() > s){
      |        ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...