QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461751 | #8831. Chemistry Class | LR# | RE | 0ms | 3768kb | C++20 | 1.3kb | 2024-07-03 00:56:58 | 2024-07-03 00:56:58 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 5;
int n, x, y;
int a[maxn], pf[maxn], dp[maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
int tst; cin >> tst; while (tst--)
{
cin >> n >> y >> x;
n *= 2;
for (int i = 1; i <= n; i++) cin >> a[i], dp[i] = 0, pf[i] = 0;
sort(a + 1, a + n + 1);
int fuck = 0;
for (int i = 1; i <= n; i += 2)
if (a[i + 1] - a[i] > y)
{
cout << "-1\n";
fuck = 1;
break;
}
if (fuck == 1) continue;
for (int i = 2; i <= n; i++)
pf[i] = pf[i - 2] + (a[i] - a[i - 1] <= x);
queue<int> q;
q.emplace(1);
for (int i = 2; i <= n; i++)
{
for (; q.size() && a[i] - a[q.front()] > y; q.pop());
if (q.size()) dp[i] = max(dp[i - 1], dp[q.front() - 1] + pf[i] - pf[q.front()]);
while (q.size() && dp[q.front() - 1] - pf[q.front()] < dp[i - 1] - pf[i])
q.pop();
q.emplace(i);
}
cout << dp[n] << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
input:
4 1 2 1 42 69 2 3 1 1 2 3 4 2 5 1 6 1 3 4 5 19 1 1 7 8 9 10 11 12 13 14 20
output:
-1 2 1 4
result:
ok 4 number(s): "-1 2 1 4"
Test #2:
score: -100
Runtime Error
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...