Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- struct prt{
- ll r, b, id;
- };
- bool cmp(prt a, prt b) {
- return a.r < b.r;
- }
- struct res{
- ll spent, id, M, rk;//M: M - 1 -- макс кроме нас
- void see() {
- cout << "res\n";
- cout << "spent id M rk\n";
- cout << spent << ' '<< id << ' ' << M << ' ' << rk << "\n\n";
- }
- };
- bool cmp1(res a, res b) {
- return a.spent < b.spent;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n; cin >> n;
- vector <prt> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i].r >> a[i].b;
- a[i].id = i;
- }
- sort(a.begin(), a.end(), cmp);
- vector <ll> pf(n);
- pf[0] = a[0].r;
- for (int i = 0; i < n; ++i) {
- pf[i] = pf[i - 1] + a[i].r;
- }
- vector <res> ans;
- for (int i = 0; i < n; ++i) {
- ll L = a[i].r, R = a[n - 1].r, M, ad;
- int lk, rk, mk;
- while (L + 1 < R) {
- M = (L + R) / 2;
- lk = i - 1;
- rk = n - 1;
- while (lk + 1 < rk) {
- mk = (lk + rk) / 2;
- if (a[mk].r >= M) {
- rk = mk;
- } else {
- lk = mk;
- }
- }
- ll del = 0;
- if (rk > 0) {
- del = pf[rk - 1];
- }
- ad = pf[n - 1] - del - M * (n - rk - 1);
- if (a[i].r + ad >= M) {
- R = M;
- } else {
- L = M;
- }
- }
- //НЕТ!!! СРАЗУ ТУТ НАДО ДЕЛАТЬ ПРОВЕРКУ НА ОПТИМАЛЬНОСТЬ
- ll spent = a[i].r + ad - M; //тк нам доостаточно уровня M!!!
- //а зная итоговое rk res, мы смодем восстановить, что каким-то партиям мы вернем срезанные голоса
- res now = {spent, a[i].id, M, rk};
- ans.push_back(now);
- }
- sort(ans.begin(), ans.end(), cmp1);
- cout << "ans\n";
- ans[0].see();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement