Submission #212425

# Submission time Handle Problem Language Result Execution time Memory
212425 2020-03-22T23:21:10 Z mode149256 Hiring (IOI09_hiring) C++14
100 / 100
622 ms 48040 KB
/*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
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
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 9 ms 1088 KB Output is correct
12 Correct 8 ms 1216 KB Output is correct
13 Correct 9 ms 1024 KB Output is correct
14 Correct 14 ms 1728 KB Output is correct
15 Correct 13 ms 1728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 16 ms 2112 KB Output is correct
5 Correct 37 ms 5568 KB Output is correct
6 Correct 289 ms 27752 KB Output is correct
7 Correct 275 ms 41028 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 416 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 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 11604 KB Output is correct
2 Correct 104 ms 11500 KB Output is correct
3 Correct 95 ms 11500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 20696 KB Output is correct
2 Correct 124 ms 20712 KB Output is correct
3 Correct 137 ms 20712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 44576 KB Output is correct
2 Correct 366 ms 44512 KB Output is correct
3 Correct 362 ms 44640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 47972 KB Output is correct
2 Correct 492 ms 47972 KB Output is correct
3 Correct 622 ms 48040 KB Output is correct