File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments