#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));}
ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
struct FenwickTree{
int n;
vector<ll> a;
FenwickTree(int _n){
n = _n;
a.resize(n+1);
}
void update(int i, ll v){
while(i <= n){
a[i] += v;
i += LASTBIT(i);
}
}
ll get(int i){
ll ans = 0;
while(i > 0){
ans += a[i];
i -= LASTBIT(i);
}
return ans;
}
ll get(int l, int r){return get(r) - get(l-1);}
int binary_lift(ll x){
int p = MASK(logOf(n)), idx =0;
while(p > 0){
if (idx + p <= n && x >= a[idx + p]){
idx += p;
x -= a[idx];
}
p >>= 1;
}
return idx;
}
};
ostream& operator << (ostream &os, pair<ll, ll> x){
os << "(" << x.first << ", " << x.second << ")";
return os;
}
void solve(){
int n; cin >> n;
ll w; cin >> w;
vector<pair<int, int>> a(n);
for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
vector<array<int, 3>> arr(n);
for(int i = 0; i < n; ++i) arr[i] = {{(int)a[i].first, (int)a[i].second, i}};
sort(ALL(a), [](pair<ll, ll> x, pair<ll, ll> y){
return x.first * y.second < y.first * x.second;
});
sort(ALL(arr), [](array<int, 3> x, array<int, 3> y){
return x[0] * y[1] < y[0] * x[1];
});
vector<pair<int, int>> val;
for(int i = 0; i < n; ++i) val.push_back(make_pair(a[i].second, i));
sort(ALL(val));
FenwickTree bit(n), sum(n);
int optimal_idx = 0;
int best_cnt = 0;
pair<ll, ll> best_val = make_pair(1, 0);
for(int i = 0; i < n; ++i){
pair<int, int> cur = make_pair(a[i].second, i);
int idx = lower_bound(ALL(val), cur) - val.begin() + 1;
bit.update(idx, 1);
sum.update(idx, a[i].second);
ll afford = w * a[i].second / a[i].first;
idx = sum.binary_lift(afford);
int cnt = bit.get(idx);
ll s = sum.get(idx);
pair<ll, ll> cur_val = make_pair(s * a[i].first, a[i].second);;
if (maximize(best_cnt, cnt)){
optimal_idx = i;
best_val = cur_val;
}
else if (best_cnt == cnt){
if (best_val.first * cur_val.second > cur_val.first * best_val.second){
optimal_idx = i;
best_val = cur_val;
}
}
}
vector<int> ans;
for(int i = 0; i < n; ++i) if ((int) ans.size() < best_cnt){
if (val[i].second <= optimal_idx){
ans.push_back(arr[val[i].second][2] + 1);
}
}
cout << ans.size() << "\n";
sort(ALL(ans));
printArr(ans, "\n", "");
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
solve();
cerr << "Time elapsed: " << clock() - start << "ms!\n";
return 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... |