이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*input
17 5862
19418 11899
688 748
846 909
506 684
516 368
265 802
464 55
14014 9205
6089 4279
613 481
13911 10444
11073 9160
141 643
4205 2955
13153 11233
971 16
7553 5487
*/
#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 (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;
}
while (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;
}
}
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 |
---|
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... |