Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <string>
- #include <set>
- #include <cmath>
- #include <map>
- #include <unordered_map>
- #include <numeric>
- #include <random>
- #include <memory>
- #include <chrono>
- #include <iterator>
- #include <functional>
- #ifdef LOCAL
- #include "debug.h"
- #else
- #define debug(x...)
- #endif
- //#pragma GCC optimize("Ofast")
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair <int, int> pii;
- #define mp make_pair
- #define pb push_back
- #define sz(x) int((x).size())
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- const int N = 1e5 + 7;
- const int inf = INT_MAX / 2;
- const ll INF = LLONG_MAX / 3;
- const int MOD = 998244353;
- const ld eps = 1e-6;
- const string cars[] = {"🚗", "🚕", "🚙"};
- signed main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cout << fixed << setprecision(3);
- cin.tie();
- cout.tie();
- ll n, ans = 0, c = 0;
- cin >> n;
- vector < pair < ll, ll > > a(n);
- vector < ll > p(n + 1);
- for (auto& [x, y] : a) {
- cin >> x >> y;
- }
- sort(a.begin(), a.end());
- for (int i = 0; i < n; i++) {
- p[i + 1] = p[i] + a[i].first;
- }
- debug(p);
- for (int i = n - 1; i >= 0; i--) {
- debug(a[i].first, p[i] + c);
- if (a[i].first >= p[i] + c) {
- ll x = ((a[i].first - (p[i] + c)) / 2 + 1);
- debug(x);
- ans += a[i].second * x;
- c += x;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement