Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning (disable : 4996)
- #pragma comment(linker, "/STACK:36777216")
- #include <stdlib.h>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <assert.h>
- #include <stack>
- #include <algorithm>
- #include <ios>
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <queue>
- #include <set>
- #include <functional>
- #include <cmath>
- #include <sstream>
- #include <map>
- #include <memory.h>
- #include <stdio.h>
- #include <cassert>
- #include <string.h>
- #include <deque>
- #include <ctime>
- #include <unordered_map>
- #include <list>
- #define forn(i , n) for (i64 i = 0; i < n; ++i)
- #define down(i, n) for (int i = (n) - 1; i >= 0; --i)
- using namespace std;
- typedef unsigned long long int u64;
- typedef long long int i64;
- typedef vector<int> vint;
- typedef vector<i64> vi64;
- typedef pair<int, int> pint;
- typedef pair<i64, i64> pi64;
- #define FILE_NAME "file"
- #define CONTEST "seq"
- #define M_PI 3.14159265358979323846
- #define ALL(a) (a).begin(), (a).end()
- const int inf = 1000000000;
- #define MOD 1000000007
- #define EPS 10E-10
- const int N = 2000000;
- struct Event
- {
- int a, o, i;
- bool operator<(const Event & b) const
- {
- return a < b.a;
- }
- };
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout << fixed << setprecision(15);
- srand(16);
- int start = clock();
- #ifdef FILE_INPUT
- freopen(FILE_NAME ".in", "r", stdin);
- freopen(FILE_NAME ".out", "w", stdout);
- #endif
- int n;
- cin >> n;
- vector<pint> arr(n);
- vector<Event> events;
- forn(i, n)
- {
- cin >> arr[i].first >> arr[i].second;
- Event a;
- a.a = arr[i].first;
- a.i = i;
- a.o = 0;
- events.push_back(a);
- a.a = arr[i].second;
- a.o = 1;
- events.push_back(a);
- }
- sort(events.begin(), events.end());
- int l = 0, r = 10000 / n + 1;
- while (r - l > 1)
- {
- int m = (r + l) / 2;
- vector<int> want(n, m);
- set<int> available;
- vector<int> will(n, 0);
- int currE = 0;
- forn(i, 10001)
- {
- while (currE < events.size() && i >= events[currE].a)
- {
- int j = events[currE].i;
- if (events[currE].o == 0)
- {
- available.insert(j);
- will[j] = arr[j].second - arr[j].first;
- }
- else
- {
- available.erase(j);
- }
- currE++;
- }
- int bestToEat = -1;
- int res = -1000000000;
- for (auto & j : available)
- {
- int c = want[j] - will[j];
- if (want[j] && c > res)
- {
- bestToEat = j;
- res = c;
- }
- will[j]--;
- }
- if (bestToEat != -1)
- {
- want[bestToEat]--;
- }
- }
- bool bad = false;
- forn(i, n)
- {
- if (want[i] > 0)
- {
- r = m;
- bad = true;
- break;
- }
- }
- if (!bad)
- {
- l = m;
- }
- }
- cout << l * n;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement