QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#689972#7750. Revenge on My BosszhenghanyunWA 0ms5772kbC++141.8kb2024-10-30 19:29:232024-10-30 19:29:24

Judging History

你现在查看的是最新测评结果

  • [2024-10-30 19:29:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5772kb
  • [2024-10-30 19:29:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 1e5 + 5;

ll T, n, S, a[N], b[N], c[N];

ll p[N], q[N];

vector <ll> vec1, vec2;

inline bool check(ll k) {
	vec1.clear();
	vec2.clear();
	for (int i = 1; i <= n; ++i) {
		p[i] = a[i] -  b[i];
		q[i] = k / c[i] - S + a[i];
		if (p[i] <= 0) {
			vec1.emplace_back(i);
		} else {
			vec2.emplace_back(i);
		}
	}
	sort(vec1.begin(), vec1.end(), [](ll x, ll y) {
		return q[x] > q[y];
	});
	sort(vec2.begin(), vec2.end(), [](ll x, ll y) {
		return q[x] - p[x] > q[y] - p[y];
	});
	ll t = 0;
	for (auto u: vec1) {
		if (t > q[u]) {
			return false;
		}
		t += p[u];
	}
	for (auto u: vec2) {
		if (t > q[u]) {
			return false;
		}
		t += p[u];
	}
	return true;
}

inline void print(ll k) {
	vec1.clear();
	vec2.clear();
	for (int i = 1; i <= n; ++i) {
		p[i] = a[i] -  b[i];
		q[i] = k / c[i] - S + a[i];
		if (p[i] <= 0) {
			vec1.emplace_back(i);
		} else {
			vec2.emplace_back(i);
		}
	}
	sort(vec1.begin(), vec1.end(), [](ll x, ll y) {
		return q[x] > q[y];
	});
	sort(vec2.begin(), vec2.end(), [](ll x, ll y) {
		return q[x] - p[x] > q[y] - p[y];
	});
	for (auto u: vec1) {
		cout << u << " ";
	}
	for (auto u: vec2) {
		cout << u << " ";
	}
	cout << "\n";
}

inline void solve() {
	cin >> n;
	S = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		S += b[i];
	}
	ll l = 1, r = 2e18;
	while (l <= r) {
		ll mid = (l + r) >> 1;
		if (check(mid)) {
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	print(l);
}

int main() {
	#ifdef LOCAL
		assert(freopen("test.in", "r", stdin));
		assert(freopen("test.out", "w", stdout));
	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5772kb

input:

2
4
1 1 4
5 1 5
1 9 1
9 8 1
9
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 8
3 2 7

output:

3 1 4 2 
3 4 8 2 6 1 7 9 5 

result:

wrong answer Wrong Answer on Case#1