/*input
5 37819
19739 14341
8878 7344
6477 7829
8200 9300
13623 13623
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
struct ppl {
ll S, Q;
int i;
};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N;
ll W;
cin >> N >> W;
vector<ppl> sk(N);
for (int i = 0; i < N; ++i)
{
int a, b; cin >> a >> b;
sk[i] = {a, b, i + 1};
}
sort(sk.rbegin(), sk.rend(), [&](const ppl & a, const ppl & b) {
return a.Q * b.S < b.Q * a.S;
});
int kiek = 0;
int l = 1;
ll sumokejau = MOD;
multiset<ll> buvo;
ll sumQ = 0;
if (sk[0].Q <= W) {
kiek = 1;
l = 0;
sumokejau = sk[0].Q;
}
buvo.insert(sk[0].Q);
// it first not included [0; it-1] it
auto it = buvo.begin();
int j = 0;
// for (auto u : sk)
// printf("%d %lld %lld\n", u.i, u.S, u.Q);
// printf("\n");
for (int i = 1; i < N; ++i)
{
sumQ += sk[i].Q;
while (j and sumQ * sk[i].S > W * sk[i].Q) {
j--;
it--;
sumQ -= *it;
}
if (j + 1 <= i and (sumQ + *it) * sk[i].S <= W * sk[i].Q) {
sumQ += *it;
it++;
j++;
}
if (sumQ * sk[i].S <= W * sk[i].Q) {
if (j + 1 > kiek
or (j + 1 == kiek
and sumQ * sk[i].S * sk[l].Q < sumokejau * sk[i].Q)) {
kiek = j + 1;
l = i;
sumokejau = sumQ * sk[i].S;
}
}
// printf("i = %d, sumQ = %d, kiek = %d\n", i, sumQ, j + 1);
buvo.insert(sk[i].Q);
sumQ -= sk[i].Q;
if (it == buvo.end() or sk[i].Q < *it) {
sumQ += sk[i].Q;
j++;
}
}
vector<ppl> ans;
for (int i = 0; i < l; ++i)
ans.push_back(sk[i]);
sort(ans.begin(), ans.end(), [&](const ppl a, const ppl b) {
return a.Q < b.Q;
});
printf("%d\n", kiek);
printf("%d\n", sk[l].i);
for (int i = 0; i < kiek - 1; ++i)
printf("%d\n", ans[i].i);
// printf("l = %d, id = %d\n", l, sk[l].i);
}
/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
640 KB |
Output is correct |
9 |
Correct |
7 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
8 ms |
1088 KB |
Output is correct |
12 |
Correct |
9 ms |
1280 KB |
Output is correct |
13 |
Correct |
9 ms |
1024 KB |
Output is correct |
14 |
Correct |
15 ms |
1728 KB |
Output is correct |
15 |
Correct |
13 ms |
1728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Incorrect |
5 ms |
388 KB |
Output isn't correct |
4 |
Correct |
18 ms |
2112 KB |
Output is correct |
5 |
Correct |
36 ms |
5560 KB |
Output is correct |
6 |
Correct |
331 ms |
27880 KB |
Output is correct |
7 |
Correct |
283 ms |
40932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
11500 KB |
Output is correct |
2 |
Correct |
108 ms |
12756 KB |
Output is correct |
3 |
Correct |
117 ms |
12728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
20712 KB |
Output is correct |
2 |
Correct |
138 ms |
22976 KB |
Output is correct |
3 |
Correct |
134 ms |
22760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
44640 KB |
Output is correct |
2 |
Correct |
382 ms |
49376 KB |
Output is correct |
3 |
Correct |
379 ms |
49376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
524 ms |
48084 KB |
Output is correct |
2 |
Correct |
536 ms |
53476 KB |
Output is correct |
3 |
Correct |
542 ms |
53332 KB |
Output is correct |