QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732979 | #8548. China Convex Polygon Contest | arnold518# | WA | 17ms | 3996kb | C++17 | 1.5kb | 2024-11-10 16:43:51 | 2024-11-10 16:43:52 |
Judging History
answer
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long long lint;
const int N = 100005;
int n, m, a[N], b[N];
void solve ()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
}
a[n+1] = m;
for(int i=1;i<=n;i++) {
scanf("%d",&b[i]);
}
sort(b+1, b+1+n);
vector<pii> gugan;
vector<int> jum;
for(int i=1;i<=n;i++) {
gugan.push_back({a[i], a[i+1]});
}
for(int i=1;i<=n;i++) {
b[i] += b[i-1];
if (b[i] < m) jum.push_back(b[i]);
else break;
}
priority_queue<int> prof;
long long ans = 0;
int gi = (int)gugan.size()-1;
int zp = 0, zb = 0;
for(int i=(int)jum.size()-1;i>=0;i--) {
int cj = jum[i];
while(gi >= 0 && cj <= gugan[gi].X) {
prof.push(gugan[gi].Y - gugan[gi].X - zp + zb);
zp = 0;
zb = 0;
gi--;
}
int tp = (prof.empty() ? 0 : prof.top());
if (gi >= 0 && tp < gugan[gi].Y - cj - zp + zb) {
ans += gugan[gi].Y - cj - zp + zb;
zp = gugan[gi].Y - cj;
zb = tp;
}
else {
ans += tp;
}
if (!prof.empty()) {
prof.pop();
}
}
printf("%lld\n", ans);
}
int main()
{
//ios_base::sync_with_stdio(false); cin.tie(NULL);
int TC;
cin >> TC;
while(TC--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3996kb
input:
3 3 10 1 5 9 1 2 3 3 10 1 5 9 1 1 4 3 10 1 5 9 1 5 10
output:
9 9 7
result:
ok 3 number(s): "9 9 7"
Test #2:
score: -100
Wrong Answer
time: 17ms
memory: 3760kb
input:
10000 9 879847766 125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083 99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599 8 30 5 12 16 19 20 23 25 27 3 1 1 4 2 8 2 3 8 30 4 10 13 16 17 20 23 27 6 3 1 2 3 4 7 2 7 586479012 37693706 ...
output:
754749634 25 25 548785306 28 875933380 24 796209714 624849894 720683076 496614303 759475944 28 27 28 602343928 25 22 22 711205025 25 25 29 28 28 23 25 27 28 815497632 755946410 28 26 28 673105692 891539003 381951593 678803216 729041494 24 24 792052331 27 23 29 483836554 25 26 587805500 28 22 8041423...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '754749634'