QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639407#8548. China Convex Polygon ContestargtargWA 15ms3628kbC++201.9kb2024-10-13 19:23:222024-10-13 19:23:23

Judging History

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

  • [2024-10-13 19:23:23]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3628kb
  • [2024-10-13 19:23:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pii pair<int, int>
void solve();

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--)solve();
    return 0;
}
//const int mod = 998244353;


void solve() {
    int n;
    int m;
    cin>>n>>m;
    vector<int>a(n+1),b(n+2);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    b[n+1]=1e18;
    sort(b.begin()+1,b.end());
    a.push_back(b[1]);
    sort(a.begin()+1,a.end());
    for(int i=1;i<=n;i++){
        b[i]+=b[i-1];
//        cout<<"b== ";cout<<b[i]<<endl;;
    }

    priority_queue<int,vector<int>,greater<int>>q1,q2;
    for(int i=1;i<=n;i++){
        if(b[i]>m)break;
        auto it= lower_bound(a.begin()+1,a.end(),b[i]);
        while(it!=a.end()&&(*it)<min(m+1,b[i+1])){
            int x=*it;
            int y=m;
            it++;
            if(it!=a.end())y=*it;
//            cout<<"i== "<<i<<' ';
//            cout<<"===="<<x<<endl;
            if(1)q2.push(y-x);
            else q1.push(y-x);
        }
        auto t= lower_bound(a.begin()+1,a.end(),b[i]+1);
        int x=b[i];
        while(t!=a.end()&&(*t)<=min(m+1,b[i+1])){
            int y=m;
            y=*t;
            if(1)q1.push(y-x);
            x=y;
            t++;
        }
        while(q2.size()>i){
            q2.pop();
        }
        while(q1.size()>i){
            q1.pop();
        }
    }
    int ans=0;
    int sum=0;
    while(q1.size()){
        sum+=q1.top();
        q1.pop();
        ans=sum;
    }
    sum=0;
    while(q2.size()){
//        cout<<"---"<<q2.top()<<endl;
        sum+=q2.top();
        q2.pop();
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}
/*
2
3 13
6 7 13
1 9 999
4 14
6 7 13 14
1 9 999 999
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
25
548785306
28
875933380
27
796209714
942603170
720683076
536166430
759475944
28
27
28
886112586
27
28
27
727698126
28
27
29
28
28
28
28
27
28
815497632
755946410
28
26
28
789022217
891539003
583799124
817190966
934413263
28
28
865467960
27
27
29
488557236
27
26
604554904
28
27
8041423...

result:

wrong answer 3rd numbers differ - expected: '27', found: '25'