Algorithm
8998. 세운이는 내일 할거야
이무쿤
2019. 12. 16. 14:36
반응형
출처
https://swexpertacademy.com/main/solvingProblem/solvingProblem.do
계속 시간초과가 나는 이유를 모르겠는데,, 찾아보니 알고리즘은 내 방식과 정확히 일치 했다. 다만 pass한 사람은
자바로 구현했을 뿐..
cin에서 시간을 많이 잡아 먹는 것 같아서 ios::base_sync_with 해줬는데 안된다.
#include<iostream>
#include<queue>
using namespace std;
int main(void)
{
int test_case;
int T;
cin >> T;
for(test_case = 1; test_case <= T; ++test_case)
{
priority_queue<pair<int,int> > pr;
int N;
cin >> N;
for(int i = 0; i < N; i++)
{
int a,b;
cin >> a >> b;
pr.push({b,a});
}
int val = pr.top().first - pr.top().second;
pr.pop();
while(!pr.empty())
{
int s = pr.top().second;
int f = pr.top().first;
pr.pop();
if( val < f)
{
val -= s;
}else{
val = f-s;
}
}
cout<<"#"<<test_case<<" "<<val<<'\n';
}
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}반응형