이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f1 first
#define s2 second
// #define int long long
using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
const int MAX = 5e5 + 69;
template<class T>
struct fenwick
{
T bit[MAX];
inline void add(int x, T val)
{
for (; x < MAX; x += (x & -x))
bit[x] += val;
}
inline T sum(int x)
{
T res = 0;
for (; x > 0; x -= (x & -x))
res += bit[x];
return res;
}
};
int32_t main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
ll W;
cin >> N >> W;
vector<array<int, 4>> V(N);
for (auto &[s, q, i, idx] : V)
cin >> s >> q;
for (int i = 0; i < N; ++i)
V[i][3] = i+1;
sort(V.begin(), V.end(), [](auto &x, auto &y){
return x[1] < y[1];
});
for (int i = 0; i < N; ++i)
V[i][2] = i+1;
sort(V.begin(), V.end(), [](auto &x, auto &y){
return 1ll * x[0] * y[1] < 1ll * y[0] * x[1];
});
fenwick<ll> bit1;
fenwick<int> bit2;
int res = 0, id = -1;
for (int j = 0; j < N; ++j)
{
auto &[s, q, i, idx] = V[j];
bit1.add(i, q);
bit2.add(i, 1);
int l = 0, r = N;
while (l < r)
{
int mid = (l + r + 1) >> 1;
if (bit1.sum(mid) * s <= 1ll * W * q) l = mid;
else r = mid - 1;
}
if (bit2.sum(l) > res)
res = bit2.sum(l), id = j;
}
sort(V.begin(), V.begin()+id+1, [](auto &x, auto &y){
return x[1] < y[1];
});
cout << res << '\n';
for (int i = 0; i < res; ++i)
cout << V[i][3] << '\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... |