QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208818 | #6416. Classical Scheduling Problem | ConfucianDonut | WA | 124ms | 3648kb | C++14 | 3.5kb | 2023-10-09 21:07:57 | 2023-10-09 21:07:58 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int n,t;
struct item {
long long second;
long long first;
int id;
};
bool operator<(item a, item b) {
return (a.first<b.first);
}
bool comp(item a, item b) {
return (a.second<b.second);
}
item a[300000];
long long idx;
bool test(int x) {
if (x-1>n-1) {
return false;
}
priority_queue <long long> pq;
long long sum = 0;
for (int i=0; i<x-1; i++) {
pq.push(a[i].second);
sum+=a[i].second;
}
long long pre[n];
for (int i=x-1; i<n; i++) {
//cout << "hello" << endl;
pre[i] = sum;
if (x==1) {
continue;
}
sum+=a[i].second;
pq.push(a[i].second);
//cout << "REM:" << pq.top() << " " << sum << endl;
sum-=pq.top();
pq.pop();
}
priority_queue <long long> pt;
sum = 0;
long long suf[n];
for (int i=n-1; i>=x-1; i--) {
if (a[i].first-x>n-1-i) {
//cout << "REM:" << i << endl;
suf[i] = -1;
pt.push(a[i].second);
//cout << "ADD:" << a[i].second << " " << pt.size() << endl;
sum+=a[i].second;
continue;
}
//cout << "REQ:" << i << " " << a[i].first-x << " " << x << endl;
//cout << "CHECK:" << pt.size() << " " << a[i].second << " " << a[i].first-x << " " << (pt.size()>0) << " " << (pt.size()>(a[i].first-x)) << endl;
while (pt.size()>0&&pt.size()>max((long long)0,a[i].first-x)) {
sum-=pt.top();
//cout << "REM:" << pt.top() << endl;
pt.pop();
}
//cout << "SUM " << sum << endl;
suf[i] = sum;
sum+=a[i].second;
pt.push(a[i].second);
}
long long minans = 1e9;
long long minidx = 0;
for (int i=x-1; i<n; i++) {
if (suf[i]==-1) {
//cout << "bruh" << endl;
break;
}
//cout << pre[i] << " " << suf[i] << " " << a[i].second << endl;
if (pre[i]+suf[i]+a[i].second<minans) {
minans = pre[i]+suf[i]+a[i].second;
minidx = i;
}
}
//cout << "MIN:" << minans << " " << t << endl;
if (minans<=t) {
idx = minidx;
return true;
}else{
return false;
}
}
int main() {
int q;
cin >> q;
for (int asdf=0; asdf<q; asdf++) {
cin >> n >> t;
for (int i=0; i<n; i++) {
cin >> a[i].second >> a[i].first;
a[i].id = i;
}
sort(a,a+n);
long long step = 1<<(31-__builtin_clz(n)+1);
long long p = 0;
while (step>0) {
//cout << asdf <<":" << step << " " << p << endl;
if (test(p+step)) {
p+=step;
}
//cout << "END" << endl;
step=step>>1;
}
cout << p << endl;
if (p==0) {
cout << 0 << endl;
continue;
}
//cout << "ANS:" << idx << endl;
cout << max(p,a[idx].first) << " ";
//cout << "IDX:" << idx << endl;
if (idx>0) {
sort(a,a+idx,comp);
}
sort(a+idx+1,a+n,comp);
for (int i=0; i<p-1; i++) {
cout << a[i].id+1 << " ";
}
cout << a[idx].id+1 << " ";
for (int i=idx+1; i<idx+a[idx].first-p+1; i++) {
cout << a[i].id+1 << " ";
}cout << endl;
//cout << "TC OVER" << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
2 4 100 20 1 40 4 60 3 30 3 1 5 10 1
output:
2 3 1 4 2 0 0
result:
ok ok, 2 test cases (2 test cases)
Test #2:
score: 0
Accepted
time: 106ms
memory: 3648kb
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 21 14 16 3 18 12 9 15 53 53 22 25 37 41 15 27 4 6 48 16 54 29 5 31 3 38 42 43 44 51 35 20 2 8 30 21 52 19 34 12 7 26 9 53 33 36 46 47 10 49 24 17 40 45 39 13 1 32 23 18 50 11 28 12 12 5 12 14 4 6 1 8 7 15 2 13 16 7 15 40 8 28 41 14 13 29 38 21 37 24 11 43 33 26 10 10 7 12 9 10 29 19 5 28 22 ...
result:
ok ok, 10000 test cases (10000 test cases)
Test #3:
score: 0
Accepted
time: 124ms
memory: 3536kb
input:
10000 31 13863446 88657 7 999554 9 118529 26 847277 28 370661 19 261018 28 635679 10 228483 3 645280 9 476021 13 778546 23 325779 9 833392 1 328146 30 873417 6 327100 31 9792 26 327533 31 361518 30 74201 17 220223 12 395716 28 92721 14 296968 27 177176 14 698707 6 130653 14 639654 14 883578 27 94779...
output:
29 30 17 20 1 23 3 27 25 21 8 6 24 12 19 5 22 10 31 7 28 9 26 11 13 4 15 29 30 2 14 16 4 4 2 4 3 5 2 2 2 3 6 7 10 13 25 18 3 17 4 6 6 8 9 10 12 2 5 0 0 13 13 1 9 8 11 13 5 10 2 7 15 6 4 14 7 7 6 3 1 5 8 7 10 12 16 6 21 10 8 12 7 18 17 5 20 15 14 3 19 13 1 21 24 3 21 16 11 8 14 23 2 4 26 1 15...
result:
ok ok, 10000 test cases (10000 test cases)
Test #4:
score: -100
Wrong Answer
time: 44ms
memory: 3648kb
input:
10000 1 148649924 152343597 1 23 2873231053 341227727 2 97244309 22 382344096 18 92079917 18 716353906 4 963429195 14 131618841 1 637584871 10 210001357 11 578579097 4 246465963 6 968391199 2 950133297 8 509339869 18 427327942 11 542440792 6 451945776 11 62800058 4 275583515 14 347078482 12 49062133...
output:
0 0 23 23 13 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 1 23 23 12 1 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20 21 22 23 23 23 12 1 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20 21 22 23 23 23 12 1 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20 21 22 23 23 23 12 1 3 4 5 6 7 8 9 10 ...
result:
wrong answer too much time taken to learn the topics: 11106369512 > 2873231053 (test case 2)