QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639777#8548. China Convex Polygon ContestargtargWA 19ms3664kbC++203.1kb2024-10-13 22:23:302024-10-13 22:23:32

Judging History

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

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

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]);

    for(int i=1;i<=n;i++){
        b[i]+=b[i-1];
    }
    sort(a.begin()+1,a.end());
    priority_queue<int,vector<int>,greater<int>>q1,q2;
    queue<int>add;
    for(int i=1;i<=n;i++){
        if(b[i]>m)break;
        auto t= lower_bound(a.begin()+1,a.end(),b[i]);
        int pre1=0,pre2=0,pre3=0;
        if(q1.size()&&q1.size()==i-1)pre1=q1.top();
        auto it=t;
        if(t!=a.end())pre2=*t-b[i];
        if(t!=a.end()&&t!=a.begin()&&i!=1){
            it--;
            pre3=*t-*it;
        }
        vector<int>sz(n+1);
        while(t!=a.end()&&(*t)<=min(m+1,b[i+1])){
            int x=*t;
            t++;

            int y=m;
            if((t!=a.end()))
                y=*t;
            if(y>min(m+1,b[i+1]))continue;
//            cout<<"y== "<<y<<endl;
            q1.push(y-x);
        }
//        cout<<q1.size()<<endl;
        while(q1.size()>i){
            q1.pop();
        }
        if(q1.size()&&pre1!=0){
            if(q1.top()>pre1){
                q1.push(pre3);
            }
            else {
//                cout<<"i== "<<i<<endl;
//                cout<<pre1<<' '<<pre2<<' '<<pre3<<endl;
//                cout<<"sz-- "<<q1.size()<<endl;
                int re=q1.top(),rre=pre1;
                if(q1.size()<i){
                    re=0;
                    //rre=0;
                }
                int tmp=pre2-re;
                int tmp2=-rre+pre3;
                if(tmp2>tmp){
                    if(sz[i-1]==i-1){
                        while(q1.top()!=pre1){
                            add.push(q1.top());
                            q1.pop();
                        }
                        q1.pop();
                        while(add.size()){
                            q1.push(add.front());
                            add.pop();
                        }
                    }
                    q1.push(pre3);
                }
                else{
                    q1.push(pre2);
                }
            }
        }
        else{
            q1.push(pre3);
        }
//        cout<<"-----------";cout<<pre1<<' '<<pre2<<' '<<pre3<<endl;
        while(q1.size()>i){
            q1.pop();
        }
        while(q1.size()&&q1.top()==0){
            q1.pop();
        }
        sz[i]=q1.size();
    }
    int ans=0;
    int sum=0;
    while(q1.size()){
        sum+=q1.top();
        q1.pop();
    }
    ans=sum;
    cout<<ans<<endl;
}
/*
2
3 13
6 7 13
1 9 999
4 14
6 7 13 14
1 9 999 999

 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
 */

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

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:

1504393618
40
28
659920080
33
1506117660
30
1612613932
1855589443
936652094
752293166
397963779
39
36
56
1940355662
35
47
42
725423378
42
23
41
39
41
37
41
40
29
1010082640
824390427
45
35
37
1014365872
1313380248
1455446576
1018621148
1584438481
39
40
1598904317
28
42
41
487694756
37
27
546721512
4...

result:

wrong answer 1st numbers differ - expected: '858888761', found: '1504393618'