Skip to content

Commit 4779fc7

Browse files
authored
[20250220] BOJ / G4 / 정육점 / 권혁준
1 parent 7701249 commit 4779fc7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <vector>
5+
#include <algorithm>
6+
using namespace std;
7+
using ll = long long;
8+
int main()
9+
{
10+
cin.tie(0)->sync_with_stdio(0);
11+
12+
ll N, M;
13+
cin >> N >> M;
14+
vector<pair<ll, ll>> A(N);
15+
for (auto &[x, y] : A) cin >> y >> x;
16+
sort(A.begin(), A.end(), [](auto a, auto b) -> bool {
17+
if (a.first == b.first) return a.second > b.second;
18+
return a.first < b.first;
19+
});
20+
21+
ll s = 0, ans = (ll)3e9;
22+
for (int i = 0; i < N; ) {
23+
if (s + A[i].second >= M) ans = min(ans, A[i].first);
24+
ll p = A[i].first, temp = 0;
25+
while (i < N && A[i].first == p) {
26+
s += A[i++].second;
27+
temp += p;
28+
if (s >= M) ans = min(ans, temp);
29+
}
30+
}
31+
32+
cout << (ans == (ll)3e9 ? -1 : ans);
33+
34+
}
35+
36+
```

0 commit comments

Comments
 (0)