티스토리 뷰
문제
알고리즘
Greedy
풀이
일을 처리하는데 걸리는 시간, 일의 마감기한이 주어졌을 때 일을 시작해야하는 가장 늦은 시간을 구하는 문제입니다.
일을 마감기한에 딱 맞춰서 끝내는 것이 일을 가장 늦게 시작할 수 있을 것입니다. 마감기한이 가장 늦은 일부터 마감시간에 딱 맞게 일을 역순으로 처리해나가며 현재시간과 다음으로 처리해야할 일의 마감기한중 작은 값을 현재시간으로 취해나가며 시뮬레이션 하면 됩니다.
코드
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef pair<int, int> pii;
int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(false);
vector<pii> vt;
int N;
cin >> N;
rep(i, N) {
int a, b;
cin >> a >> b;
vt.emplace_back(b, a);
}
sort(vt.rbegin(), vt.rend());
int cur = INT_MAX;
for (auto [b, a] : vt) {
cur = min(cur, b);
cur -= a;
}
cout << (cur < 0 ? -1 : cur);
return 0;
}
'Algorithm' 카테고리의 다른 글
[백준 20970] Dance Mooves (0) | 2021.05.15 |
---|---|
[백준 20649] Stuck in a Rut (0) | 2021.05.14 |
[백준 20968] Telephone (0) | 2021.05.11 |
[백준 3015] 오아시스 재결합 (0) | 2021.05.05 |
[백준 20971] No Time to Paint (0) | 2021.04.30 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 세그먼트트리
- sorting
- spring
- knapsack
- Suffix Array
- SCC
- 이분매칭
- hld
- union find
- 2-SAT
- dfs
- Fenwick
- 트라이
- greedy
- sweeping
- spring boot
- kmp
- DP
- 정렬
- 펜윅트리
- 이분탐색
- 동적계획법
- Segment tree
- string
- dijkstra
- 스위핑
- 좌표압축
- implementation
- Oracle
- bfs
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함