QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176029 | #6416. Classical Scheduling Problem | danielkou5855 | WA | 85ms | 3580kb | C++17 | 3.2kb | 2023-09-11 08:26:23 | 2023-09-11 08:26:23 |
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<pair<int, int>, int> &a, const pair<pair<int, int>, int> &b) {
return a.first.second < b.first.second;
}
bool cmp_first(const pair<pair<int, int>, int> &a, const pair<pair<int, int>, int> &b) {
if (a.first.first == b.first.first) {
return a.second < b.second;
}
return a.first.first < b.first.first;
}
pair<bool, int> works(int m, vector<pair<pair<int, int>, int>> &arr, int smax) {
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, decltype(&cmp_first)> small(cmp_first), big(cmp_first);
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.first;
while ((int) big.size() > max(0LL, ((i == 0 ? 0 : arr[i - 1].first.second) - m))) {
running -= big.top().first.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.first <= smax) && (max(0LL, arr[i].first.second - m) + i < (int) arr.size())) {
return {true, i};
}
small.push(arr[i]);
running2 += arr[i].first.first;
while ((int) small.size() >= m) {
running2 -= small.top().first.first; small.pop();
}
}
return {false, -1};
}
void print_ans(int ans, int m, vector<pair<pair<int, int>, int>> &arr) {
cout << m << "\n";
cout << (m + max(0LL, (ans == -1 ? 0 : arr[ans].first.second) - m)) << "\n";
if ((m + max(0LL, (ans == -1 ? 0 : arr[ans].first.second) - m)) == 0) {
return;
}
cout << arr[ans].second + 1 << " ";
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, decltype(&cmp_first)> small(cmp_first), big(cmp_first);
for (int i = 0; i < ans; i++) {
small.push(arr[i]);
while ((int) small.size() >= m) {
small.pop();
}
}
set<int> p;
while (!small.empty()) {
cout << small.top().second + 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 << big.top().second + 1 << " "; big.pop();
}
cout << "\n";
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int T; cin >> T;
while (T--) {
int N, M; cin >> N >> M;
vector<pair<pair<int, int>, int>> arr(N); // a, b
for (int i = 0; i < N; i++) {
cin >> arr[i].first.first >> arr[i].first.second; arr[i].second = i;
}
sort(arr.begin(), arr.end(), cmp_second);
// for (auto p : arr) {
// cout << p.first << " " << p.second << "\n";
// }
int l = 0, r = N;
int ans = -1;
while (l < r) {
int m = l + (r - l + 1) / 2;
auto asdkljasdlfasd = works(m, arr, M);
if (asdkljasdlfasd.first) {
l = m; ans = asdkljasdlfasd.second;
} else {
r = m - 1;
}
}
print_ans(ans, l, arr);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3524kb
input:
2 4 100 20 1 40 4 60 3 30 3 1 5 10 1
output:
2 3 4 1 2 0 0
result:
ok ok, 2 test cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 85ms
memory: 3580kb
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:
7 8 9 12 18 3 16 14 21 8 53 53 29 14 11 50 18 23 32 1 13 39 45 40 17 49 24 10 47 46 36 33 53 9 26 7 12 34 19 52 21 30 8 2 20 35 51 44 43 42 38 3 31 5 54 16 48 6 4 27 15 41 37 25 22 12 12 13 9 2 15 7 8 1 6 4 14 12 5 7 14 28 1 13 14 41 8 40 18 23 39 4 29 10 10 15 22 28 5 19 29 10 9 12 7 25 20 14 8...
result:
wrong answer too much time taken to learn the topics: 2141 > 1892 (test case 1)