QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#179899 | #6416. Classical Scheduling Problem | Curious_Droid | WA | 132ms | 3628kb | C++23 | 7.0kb | 2023-09-15 12:54:42 | 2023-09-15 12:54:42 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <queue>
std::pair<std::pair<int, int>, int> topics[200000];
int n, t;
bool check(int x)
{
if(x == 0){
return true;
}
std::priority_queue<int> pq;
int sum = 0;
int prefix[n];
for (int i = 0; i < n; i++)
{
if(x == 1){
prefix[i] = 0;
continue;
}
prefix[i] = sum;
if(pq.size() != x - 1){
prefix[i] = -1;
}
//std::cout << i << ": " << prefix[i] << "\n";
int a = topics[i].first.second;
if (pq.size() < x - 1)
{
pq.push(a);
sum += a;
}
else
{
if (pq.top() > a)
{
sum += a;
sum -= pq.top();
pq.pop();
pq.push(a);
}
}
}
int suffix[n];
sum = 0;
pq = std::priority_queue<int>();
for (int i = n - 1; i >= 0; i--)
{
suffix[i] = sum;
if (i == 0)
{
break;
}
int a = topics[i].first.second;
int b = topics[i - 1].first.first;
if(pq.size() != b - x){
suffix[i] = -1;
}
if (b <= x)
{
suffix[i] = 0;
continue;
}
while (pq.size() > b - x)
{
pq.pop();
}
if (pq.size() < b - x)
{
pq.push(a);
sum += a;
}
else
{
if (pq.top() > a)
{
sum += a;
sum -= pq.top();
pq.pop();
pq.push(a);
}
}
}
for (int i = x - 1; i < n; i++)
{
int b = topics[i].first.first;
if (b <= x)
{
break;
}
int a = topics[i].first.second;
if (prefix[i] != -1 && suffix[i] != -1 && prefix[i] + a + suffix[i] <= t)
{
// std::cout << "ANS aT " << i << "\n";
// std::cout << prefix[i] << " " << a <<" " << suffix[i] << "\n";
// std::cout << b << "\n";
return true;
}
}
return false;
}
int calcans(int x)
{
std::priority_queue<int> pq;
int sum = 0;
int prefix[n];
for (int i = 0; i < n; i++)
{
if(x == 1){
prefix[i] = 0;
continue;
}
prefix[i] = sum;
//std::cout << i << ": " << prefix[i] << "\n";
int a = topics[i].first.second;
if (pq.size() < x - 1)
{
pq.push(a);
sum += a;
}
else
{
if (pq.top() > a)
{
sum += a;
sum -= pq.top();
pq.pop();
pq.push(a);
}
}
}
int suffix[n];
sum = 0;
pq = std::priority_queue<int>();
for (int i = n - 1; i >= 0; i--)
{
suffix[i] = sum;
if (i == 0)
{
break;
}
int a = topics[i].first.second;
int b = topics[i - 1].first.first;
if (b <= x)
{
suffix[i] = 0;
continue;
}
while (pq.size() > b - x)
{
pq.pop();
}
if (pq.size() < b - x)
{
pq.push(a);
sum += a;
}
else
{
if (pq.top() > a)
{
sum += a;
sum -= pq.top();
pq.pop();
pq.push(a);
}
}
}
for (int i = x - 1; i < n; i++)
{
int b = topics[i].first.first;
if (b <= x)
{
break;
}
int a = topics[i].first.second;
if (prefix[i] + a + suffix[i] <= t)
{
return i;
}
}
return -1;
}
void getans(int x)
{
int k = calcans(x);
if(k == -1){
std::cout << "0\n";
return;
}
//std::cout << k << " HERE\n";
std::priority_queue<std::pair<int, int>> pq;
for (int i = 0; i < k; i++)
{
//std::cout << i << " HERE\n";
if(x == 1){
continue;
}
int a = topics[i].first.second;
int id = topics[i].second;
if (pq.size() < x - 1)
{
pq.push({a, id});
}
else
{
if (pq.top().first > a)
{
pq.pop();
pq.push({a, id});
}
}
//std::cout << "GOTHERE\n";
}
std::priority_queue<std::pair<int, int>> pq2;
//std::cout << "HERE\n";
for (int i = n - 1; i > k; i--)
{
//std::cout << i << " HERE\n";
if (i == 0)
{
break;
}
int a = topics[i].first.second;
int b = topics[i - 1].first.first;
int id = topics[i].second;
if (b <= x)
{
continue;
}
//std::cout << "GOTHERE\n";
//std::cout << b << " " << x << "\n";
while (pq2.size() > b - x)
{
pq2.pop();
}
//std::cout << "GOTHERE2\n";
if (pq2.size() < b - x)
{
pq2.push({a, id});
}
else
{
//std::cout << "HERE\n";
if (pq2.top().first > a)
{
pq2.pop();
pq2.push({a, id});
}
}
//std::cout << "GOTHERE3\n";
}
std::vector<int> v;
while(pq.size() != 0){
v.push_back(pq.top().second+1);
//std::cout << pq.top().second+1 << "<-\n";
pq.pop();
}
while(pq2.size() != 0){
v.push_back(pq2.top().second+1);
//std::cout << pq2.top().second+1 << "<-\n";
pq2.pop();
}
v.push_back(topics[k].second+1);
std::sort(v.begin(), v.end());
std::cout << v.size() << "\n";
for(int i : v){
std::cout << i << " ";
}
std::cout << "\n";
}
int main()
{
int q;
std::cin >> q;
while (q--)
{
std::cin >> n >> t;
//std::pair<std::pair<int, int>, int> topics[n];
for (int i = 0; i < n; i++)
{
std::cin >> topics[i].first.second >> topics[i].first.first;
topics[i].second = i;
}
std::sort(topics, topics + n);
int l = 0, r = n;
while (l < r)
{
int mid = (l + r) / 2 + 1;
//std::cout << l << " " << r << " " << mid << "\n";
bool res = check(mid);
//std::cout<< res << "\n";
if (check(mid))
{
l = mid;
}
else
{
r = mid - 1;
}
}
std::cout << l << "\n";
getans(l);
std::cout.flush();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 132ms
memory: 3628kb
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:
0 0 31 32 1 2 6 7 8 11 12 15 16 18 20 21 22 24 25 26 31 35 36 38 40 42 43 44 46 47 48 49 51 52 53 54 9 10 1 4 5 6 7 8 12 14 15 16 0 0 5 6 1 7 10 22 27 28 0 0 7 8 2 5 6 9 10 11 12 13 0 0 0 0 0 0 10 11 2 3 5 6 7 8 9 10 12 13 16 7 8 3 6 7 8 9 10 11 12 0 0 39 41 1 2 3 5 6 10 12 13 14 17 20 21 22 2...
result:
wrong answer jury has a better answer: jans = 7, pans = 0 (test case 1)