QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693610#7906. Almost ConvexLi_XinyueWA 0ms3664kbC++202.1kb2024-10-31 16:27:442024-10-31 16:27:45

Judging History

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

  • [2024-10-31 16:27:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3664kb
  • [2024-10-31 16:27:44]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define MAXN 500000
using namespace std;
int T;
int N,K;
int A[MAXN+5];
priority_queue<pair<int,int> > q1;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q2;
int l=1,r=0;
int cnt1=0,cnt2=0,tmp=0,sum1=0,sum2=0,num1=0,num2=0,ans=0;

int calc(){
    return (tmp*num1-sum1)+(sum2-tmp*num2);
}
void adjust(){
    while(num1<num2){
        while(q2.top().second<l){
            q2.pop();
        }
        pair<int,int> t=q2.top();q2.pop();
        q1.push(t);
        num1++;
        num2--;
        sum1+=t.first;
        sum2-=t.first;
    }
    tmp=q1.top().first;
    while(num1>num2+1){
        while(q1.top().second<l){
            q1.pop();
        }
        pair<int,int> t=q1.top();q1.pop();
        q2.push(t);
        num1--;
        num2++;
        sum1-=t.first;
        sum2+=t.first;
    }
    tmp=q1.top().first;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--){
        while(!q1.empty())q1.pop();
        while(!q2.empty())q2.pop();
        cnt1=0,cnt2=0,tmp=0,sum1=0,sum2=0,num1=0,num2=0,ans=0;
        l=1,r=0;
        cin>>N>>K;
        for(int i=1;i<=N;i++){
            cin>>A[i];
            A[i]-=i;
        }

        for(int i=1;i<=N;i++){
            while(l<=r && calc()>K){
                if(A[l]>tmp){
                    num2--;
                    sum2-=A[l];
                }
                else{
                    num1--;
                    sum1-=A[l];
                }
                l++;
                adjust();
            }
            if(A[i]>tmp){
                q2.push(pair<int,int>{A[i],i});
                sum2+=A[i];
                num2++;
            }
            else{
                q1.push(pair<int,int>{A[i],i});
                sum1+=A[i];
                num1++;
            }
            r++;
            adjust();
            if(calc()<=K){
                ans=max(ans,num1+num2);
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3664kb

input:

7
1 4
4 0
2 3
3 1
3 5
0 0
2 4

output:

1
0
3
0
2
2
2

result:

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