Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Boxes {
- long long a;
- long long b;
- };
- bool cmp(Boxes lhs, Boxes rhs) {
- if (lhs.a < lhs.b) {
- if (rhs.a < rhs.b)
- return lhs.a < rhs.a;
- else
- return lhs.a < rhs.b;
- }
- else {
- if (rhs.a < rhs.b)
- return lhs.b < rhs.a;
- else
- return lhs.b < rhs.b;
- }
- }
- int main() {
- int n;
- long long L;
- cin >> n;
- vector<Boxes> Boxes(n);
- for (int i = 0; i < n; ++i) {
- cin >> Boxes[i].a >> Boxes[i].b;
- }
- cin >> L;
- sort(Boxes.begin(), Boxes.end(), cmp);
- int count = 0;
- int k = 0;
- while (L > 0) {
- if (L - min(Boxes[k].a, Boxes[k].b) < 0) {
- if (min(Boxes[k].a, Boxes[k].b) / 2 >= L) {
- L += min(Boxes[k - 1].a, Boxes[k - 1].b) / 2;
- if (min(Boxes[k].a, Boxes[k].b) / 2 >= L) {
- break;
- } else {
- ++count;
- break;
- }
- }
- else {
- L -= min(Boxes[k].a, Boxes[k].b) / 2;
- ++count;
- ++k;
- if (k == n)
- break;
- }
- }
- else {
- L -= min(Boxes[k].a, Boxes[k].b);
- ++count;
- ++k;
- if (k == n)
- break;
- }
- }
- if (count == 0)
- count++;
- cout << count;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement