QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#660947#6416. Classical Scheduling ProblemwangjunruiWA 62ms5828kbC++142.2kb2024-10-20 14:01:092024-10-20 14:01:10

Judging History

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

  • [2024-10-20 14:01:10]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:5828kb
  • [2024-10-20 14:01:09]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
typedef long long ll;
constexpr int N = 2e5 + 5;
int n;
ll t;
struct node
{
	int a, b, id;
	inline bool operator<(const node &rhs) const
	{
		return b < rhs.b;
	}
} a[N];
ll suf[N];
inline bool check(int mid)
{
	priority_queue<int> q;
	ll res = 0;
	for (int i = n; i >= 1; --i)
	{
		int x = max(a[i].b - mid, 0);
		while (q.size() > x)
		{
			res -= q.top();
			q.pop();
		}
		suf[i] = (q.size() == x ? res : t + 1);
		q.push(a[i].a);
		res += a[i].a; 
	}
	while (!q.empty())
		q.pop();
	res = 0;
	for (int i = 1; i <= n; ++i)
	{
		q.push(a[i].a);
		res += a[i].a;
		while (q.size() > mid)
		{
			res -= q.top();
			q.pop();
		}
		if (q.size() == mid && res + suf[i] <= t)
			return true;
	}
	return false;
}
int p[N], tot;
inline void solve(int mid)
{
	priority_queue<int> q;
	ll res = 0;
	for (int i = n; i >= 1; --i)
	{
		int x = max(a[i].b - mid, 0);
		while (q.size() > x)
		{
			res -= q.top();
			q.pop();
		}
		suf[i] = (q.size() == x ? res : t + 1);
		q.push(a[i].a);
		res += a[i].a; 
	}
	while (!q.empty())
		q.pop();
	res = 0;
	for (int i = 1; i <= n; ++i)
	{
		q.push(a[i].a);
		res += a[i].a;
		while (q.size() > mid)
		{
			res -= q.top();
			q.pop();
		}
		if (q.size() == mid && res + suf[i] <= t)
		{
			sort(a + 1, a + 1 + i, [](node x, node y) { return x.a < y.a; });
			for (int j = 1; j <= mid; ++j)
				p[++tot] = a[j].id;
			sort(a + 1 + i, a + 1 + n, [](node x, node y) { return x.a < y.a; });
			for (int j = i + 1; j <= i + max(a[i].b - mid, 0); ++j)
				p[++tot] = a[j].id;
			return;
		}
	}
}
inline void work()
{
	cin >> n >> t;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i].a >> a[i].b;
		a[i].id = i;
	}
	sort(a + 1, a + 1 + n);
	int l = 1, r = n;
	while (l <= r)
	{
		int mid = (l + r) >> 1;
		if (check(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	solve(r);
	cout << r << '\n';
	cout << tot << '\n';
	for (int i = 1; i <= tot; ++i)
		cout << p[i] << ' ';
	cout << '\n';
	tot = 0;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T = 1;
	cin >> T;
	while (T--)
		work();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5828kb

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: -100
Wrong Answer
time: 62ms
memory: 5636kb

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
7
21 14 16 3 18 9 12 
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 14 
12
12
5 12 14 4 6 1 8 7 15 2 13 9 
7
7
40 8 28 41 14 13 1 
10
10
7 12 15 9 10 29 19 5 28 22 
0
0

10
10
5 13 2 9 8 12 7...

result:

wrong answer actual and declared scores differ: actual = 6, declared = 7 (test case 1)