QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#175945 | #6416. Classical Scheduling Problem | danielkou5855 | WA | 86ms | 3620kb | C++17 | 2.8kb | 2023-09-11 06:22:21 | 2023-09-11 06:22:22 |
Judging History
answer
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool cmp_second(const pair<int, int> &a, const pair<int, int> &b) {
return a.second < b.second;
}
bool cmp_first(const pair<int, int> &a, const pair<int, int> &b) {
return a.first < b.first;
}
pair<bool, int> works(int m, vector<pair<int, int>> &arr, int smax) {
priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(&cmp_second)> small(cmp_second), big(cmp_second);
if (smax == 0) {
return make_pair(true, -1);
}
vector<int> dp((int) arr.size());
int running = 0;
for (int i = (int) arr.size() - 1; i >= 0; i--) {
dp[i] = running;
big.push(arr[i]);
running += arr[i].first;
if (i == 0) continue;
while ((int) big.size() > max(0LL, arr[i - 1].second - m)) {
running -= big.top().first; big.pop();
}
}
int running2 = 0; // less than
for (int i = 0; i < (int) arr.size(); i++) {
if ((i + 1 >= m) && (running2 + dp[i] + arr[i].first <= smax) && (max(0LL, arr[i].second - m) + i < (int) arr.size())) {
return {true, i};
}
small.push(arr[i]);
running2 += arr[i].first;
while ((int) small.size() >= m) {
running2 -= small.top().first; small.pop();
}
}
return {false, -1};
}
map<pair<int, int>, int> r;
void print_ans(int ans, int m, vector<pair<int, int>> &arr) {
cout << m << "\n";
cout << (ans == -1 ? 0 : m + max(0LL, arr[ans].second - m)) << "\n";
if (ans == -1) {
return;
}
priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(&cmp_second)> small(cmp_second), big(cmp_second);
for (int i = 0; i < ans; i++) {
small.push(arr[i]);
while ((int) small.size() >= m) {
small.pop();
}
}
while (!small.empty()) {
cout << r[small.top()] + 1 << " "; small.pop();
}
for (int i = (int) arr.size() - 2; i >= ans; i--) { // so i don't have to commit a war crime like in bsearch validation functoin
big.push(arr[i + 1]);
while ((int) big.size() > max(0LL, arr[i].second - m)) {
big.pop();
}
}
while (!big.empty()) {
cout << r[big.top()] + 1 << " "; big.pop();
}
cout << r[arr[ans]] + 1 << "\n";
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int T; cin >> T;
while (T--) {
int N, M; cin >> N >> M;
vector<pair<int, int>> arr(N); // a, b
r.clear();
for (int i = 0; i < N; i++) {
cin >> arr[i].first >> arr[i].second;
r[arr[i]] = i;
}
sort(arr.begin(), arr.end(), cmp_second);
int l = 0, r = N;
int tmp = 0; int ans = -1;
while (l < r) {
int m = l + (r - l + 1) / 2;
auto tmp = works(m, arr, M);
if (tmp.first) {
l = m; ans = tmp.second;
} else {
r = m - 1;
}
}
print_ans(ans, l, arr);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3468kb
input:
2 4 100 20 1 40 4 60 3 30 3 1 5 10 1
output:
2 3 1 2 4 0 0
result:
ok ok, 2 test cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 86ms
memory: 3620kb
input:
10000 21 1892 174 13 604 15 170 2 413 11 899 2 531 12 651 17 553 9 429 8 837 14 937 12 577 7 532 11 19 2 173 10 165 6 762 15 221 6 945 13 302 19 7 3 54 26066 812 31 432 24 240 37 171 39 204 47 174 30 569 1 467 5 624 42 734 35 907 3 568 23 802 40 991 32 119 13 187 27 739 42 891 14 550 44 374 16 483 1...
output:
6 6 18 21 14 5 3 16 53 53 5 50 30 39 19 27 41 17 9 37 13 23 4 3 33 22 10 34 46 45 14 32 1 47 6 52 44 42 26 16 48 35 2 31 12 36 40 24 21 20 49 18 15 43 53 25 51 38 8 11 7 54 29 12 12 2 9 12 15 14 4 5 6 7 1 8 13 1 4 17 40 15 31 8 8 12 22 3 10 1 7 28 9 0 0 9 9 4 5 6 9 10 11 2 12 7 0 0 0 0 0 0 15 15 1 5...
result:
wrong answer jury has a better answer: jans = 7, pans = 6 (test case 1)