하루 1문제 챌린지/Silver3

백준 12018번 Yonsei TOTO (C++)

그린푸딩 2024. 2. 15. 22:36
728x90
반응형

https://www.acmicpc.net/problem/12018

 

12018번: Yonsei TOTO

연세대학교 수강신청이 얼마 전부터 바뀌어, 마일리지 제도로 바뀌었다. 이 제도는 각각의 학생들에게 마일리지를 주어 듣고 싶은 과목에 마일리지를 과목당 1~36을 분배한다. 그리고 모두 분배

www.acmicpc.net

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<vector>
#include<queue>

using namespace std;

priority_queue<int,vector<int>,greater<int>>pq;

int main()
{
    int n,m;//과목수, 마일리지 
    cin>>n>>m;
    
    int p,l; //수강신청한 사람수, 수강인원
    for(int i=0;i<n;i++){
        cin>>p>>l;
        priority_queue<int,vector<int>,less<int>>tmp;
        
        int t;
        for(int j=0;j<p;j++){
            cin>>t;
            tmp.push(t);
        }
        
        if(p<l){ //마일리지 1개 
            pq.push(1);
        }
        else{
            int s=l-1;
            while(s--){
                tmp.pop();
            }
            pq.push(tmp.top());
            
        }
    }
    
    int cnt=0;

    //1 14 20 25 36
   
    
    while(1){
        if((m-pq.top())>=0){
            cnt++;
            m-=pq.top();
            pq.pop();

           
        }
        else{
            break;
        }
        if(pq.empty())break;
    }
  
    cout<<cnt;


    return 0;
}
728x90
반응형