- 문제 링크 : boj.kr/7983
- 난이도 : 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;
}
풀이
#1263과 제한만 다른 같은 문제이다.
728x90
'PS' 카테고리의 다른 글
BOJ 32031 : 석고 모형 만들기 (0) | 2024.07.16 |
---|---|
BOJ 16043 : Missing Gnomes (0) | 2024.07.15 |
BOJ 13269 : 쌓기나무 (1) | 2024.07.13 |
BOJ 24524 : 아름다운 문자열 (0) | 2024.07.12 |
BOJ 31719 : UDP 스택 (0) | 2024.07.11 |