제출 #167005

#제출 시각아이디문제언어결과실행 시간메모리
167005itgl학교 설립 (IZhO13_school)C++14
15 / 100
2043 ms12356 KiB
#include<bits/stdc++.h>
#define ss second
#define pb push_back
#define mp make_pair
#define ff first

using namespace std;

int n,m,s;
priority_queue<pair<int,int> > pq,pq1;
int main(){
  cin >> n >> m >> s;

  for(int i=1;i<=n;i++){
    int x,y;
    cin >> x >> y;
    pq.push(mp(x,x-y));
  }
  int res=0;
  while(!pq.empty()){
    if(m>0){
      if(pq.top().ss>0&&s<=0){
        res+=pq.top().ff;

        pq.pop();
        m--;
      }else if(s>0){
        pq1.push(mp(pq.top().ff-pq.top().ss,-pq.top().ss));
        pq.pop();
      }

    }
    else{
      pq1.push(mp(pq.top().ff-pq.top().ss,-pq.top().ss));
      pq.pop();
    }
  }
  while(!pq1.empty()){
    if(s>0){
      res+=pq1.top().ff;
      pq1.pop();
      s--;
    }
    else {
      pq.push(mp(pq1.top().ff-pq1.top().ss,-pq.top().ss));
      pq1.pop();
    }
  }
  while(m--){
    res+=pq.top().ff;
    pq.pop();
  }


  cout << res;

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...