#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;
double 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 * a[i].first.first * 1.0 / a[i].first.second;
}
else if(cnt == ans1 && amt * a[i].first.first * 1.0 / a[i].first.second < ans2) {
id = i;
ans2 = amt * a[i].first.first * 1.0 / a[i].first.second;
}
}
cout << ans1 << '\n';
if(ans1 == 0) return;
vector<pair<int,int>> bruh;
for(int i=1; i<=id; i++) {
bruh.push_back({a[i].first.second, a[i].second});
}
sort(bruh.begin(), bruh.end());
for(int i=0; i<ans1; i++) cout << bruh[i].second << "\n";
}
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
856 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
3 ms |
860 KB |
Output is correct |
11 |
Correct |
3 ms |
1116 KB |
Output is correct |
12 |
Correct |
4 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
860 KB |
Output is correct |
14 |
Correct |
6 ms |
1312 KB |
Output is correct |
15 |
Correct |
6 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
9 ms |
1524 KB |
Output is correct |
5 |
Correct |
20 ms |
4488 KB |
Output is correct |
6 |
Correct |
132 ms |
12880 KB |
Output is correct |
7 |
Correct |
167 ms |
21192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
824 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
6428 KB |
Output is correct |
2 |
Correct |
52 ms |
7420 KB |
Output is correct |
3 |
Correct |
55 ms |
6580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
10700 KB |
Output is correct |
2 |
Correct |
86 ms |
10880 KB |
Output is correct |
3 |
Correct |
83 ms |
12972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
209 ms |
21200 KB |
Output is correct |
2 |
Correct |
198 ms |
21192 KB |
Output is correct |
3 |
Correct |
212 ms |
21244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
23136 KB |
Output is correct |
2 |
Correct |
229 ms |
23292 KB |
Output is correct |
3 |
Correct |
225 ms |
23108 KB |
Output is correct |