PS
BOJ 1263 : 시간 관리
lickelon
2024. 7. 4. 22:20
- 문제 링크 : boj.kr/1263
- 난이도 : G5
- 태그 : 그리디, 정렬
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
bool comp(pii &a, pii &b) {
return a.second > b.second;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<pii> arr(n);
for(auto &u : arr) {
cin >> u.first >> u.second;
}
sort(all(arr), comp);
int ans = INF;
for(auto u : arr) {
ans = min(ans, u.second);
ans -= u.first;
}
cout << (ans < 0 ? -1 : ans);
return 0;
}
풀이
일을 시작하는 시간을 최대한 뒤로 밀어야 한다.
데드라인이 늦는 순으로 최대한 미뤄서 일을 하면 된다.
728x90