This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
static void run_with_stack_size(void (*func)(void), size_t stsize) {
char *stack, *send;
stack = (char *)malloc(stsize);
send = stack + stsize - 16;
send = (char *)((uintptr_t)send / 16 * 16);
asm volatile(
"mov %%rsp, (%0)\n"
"mov %0, %%rsp\n"
:
: "r"(send));
func();
asm volatile("mov (%0), %%rsp\n" : : "r"(send));
free(stack);
}
bool cmp(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
return x.first.first * y.first.second < y.first.first * x.first.second;
}
int bit[20202];
void add(int x, int v) {
for(;x<20202;x+=x&-x)bit[x]+=v;
}
int sum(int x) {
int s=0;
for(;x;x-=x&-x)s+=bit[x];
return s;
}
int bit2[20202];
void add2(int x, int v) {
for(;x<20202;x+=x&-x)bit2[x]+=v;
}
int sum2(int x) {
int s=0;
for(;x;x-=x&-x)s+=bit2[x];
return s;
}
void solve(int tc) {
int n, w;
cin >> n >> w;
pair<pair<int, int>, int> a[n+1];
for(int i=1; i<=n; i++) {
cin >> a[i].first.first >> a[i].first.second;
a[i].second = i;
}
sort(a+1, a+1+n, cmp);
int ans1 = 0, ans2 = 1e18;
int id = 0;
for(int i=1; i<=n; i++) {
int u = w * a[i].first.second / a[i].first.first;
add(a[i].first.second, 1);
add2(a[i].first.second, a[i].first.second);
int lb = 0, rb = 20000;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
if(sum2(mid) <= u) lb = mid;
else rb = mid - 1;
}
int cnt = sum(lb);
int bruh = (u - sum2(lb)) / (lb + 1);
bruh = min(bruh, sum(lb + 1) - sum(lb));
cnt += bruh;
int amt = sum2(lb) + bruh * (lb + 1);
if(cnt > ans1) {
id = i;
ans1 = cnt;
ans2 = amt;
}
else if(cnt == ans1 && amt < ans2) {
id = i;
ans2 = amt;
}
}
cout << ans1 << '\n';
if(ans1 == 0) return;
}
void uwu() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
int32_t main() {
#ifdef ONLINE_JUDGE
uwu();
#endif
#ifndef ONLINE_JUDGE
run_with_stack_size(uwu, 1024 * 1024 * 1024); // run with a 1 GiB stack
#endif
}
/*
g++ C.cpp -std=c++17 -O2 -o C
./C < input.txt
*/
Compilation message (stderr)
hiring.cpp: In function 'void solve(long long int)':
hiring.cpp:69:7: warning: variable 'id' set but not used [-Wunused-but-set-variable]
69 | int id = 0;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |