QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666108#8548. China Convex Polygon ContestWedonotLikeStudying#WA 7ms3732kbC++201.8kb2024-10-22 16:38:272024-10-22 16:38:28

Judging History

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

  • [2024-10-22 16:38:28]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3732kb
  • [2024-10-22 16:38:27]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXN 100000
#define rep(i,j,k) for (int i=(j);i<=(k);++i)
#define dep(i,j,k) for (int i=(j);i>=(k);--i)
using namespace std;
typedef long long LL;

priority_queue <int> grd;
int a[MAXN+5];
LL b[MAXN+5];

void solve() {
    int n,m;
    cin>>n>>m;
    rep(i,1,n) cin>>a[i];
    rep(i,1,n) cin>>b[i];
    sort(b+1,b+n+1);
    rep(i,1,n) b[i]+=b[i-1];
    a[n+1]=m;
    int l=1,r=1;
    LL ans=0;
    while (!grd.empty()) grd.pop();
    rep(i,1,n+1) {
        while (l<=n&&b[l]<a[i-1]) ++l;
        while (r<=n&&b[r]<a[i]) ++r;
        if (l<r) {
            if (!grd.empty()) {
                if (a[i]-a[i-1]+grd.top()>a[i]-b[l]) {
                    ans+=a[i]-a[i-1]+grd.top();
                    grd.pop();
                    grd.push(-a[i]+a[i-1]);
                    grd.push(0);
                } else {
                    ans+=a[i]-b[l];
                    if (a[i]-a[i-1]+grd.top()>0) {
                        int tmp=a[i]-a[i-1]+grd.top();
                        grd.pop();
                        grd.push(-a[i]+b[l]+tmp);
                    } else grd.push(-a[i]+b[l]);
                }
            } else {
                ans+=a[i]-b[l];
                grd.push(-a[i]+b[l]);
            }
            rep(j,l+1,r-1) {
                grd.push(0);
            }
        } else {
            if (!grd.empty()) {
                if (a[i]-a[i-1]+grd.top()>0) {
                    ans+=a[i]-a[i-1]+grd.top();
                    grd.pop();
                    grd.push(-a[i]+a[i-1]);
                }
            }
        }
    }
    cout<<ans<<"\n";
    return;
}

int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

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: 7ms
memory: 3732kb

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:

858888761
28
27
548785306
28
875933380
27
803763192
942603170
720683076
536166430
759475944
28
27
28
886112586
27
28
28
727698126
28
27
29
28
28
28
28
27
28
819730903
755946410
28
26
28
792662140
891539003
583799124
817190966
934413263
28
28
865467960
27
27
29
488557236
27
26
618111955
28
26
8328741...

result:

wrong answer 51st numbers differ - expected: '27', found: '26'