QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673564#5417. Chat ProgramcabbageaWA 1160ms22628kbC++171.6kb2024-10-25 00:00:212024-10-25 00:00:21

Judging History

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

  • [2024-10-25 00:00:21]
  • 评测
  • 测评结果:WA
  • 用时:1160ms
  • 内存:22628kb
  • [2024-10-25 00:00:21]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=1e6+10;

int n,m;
int a[N]; int b[N];
int k; int c,d;
int pre[N],post[N]; 
int check(int mid){
    for(int i=1;i<=n;i++) b[i]=a[i]-mid;
    for(int i=1;i<=n;i++)
    {
        pre[i]=pre[i-1];
        if(b[i]>=0) pre[i]++;
    }
    post[n+1]=0;
    for(int i=n;i>=1;i--) 
    {
        post[i]=post[i+1];
        if(b[i]>=0) post[i]++;
    }
    set<pair<int,int> > s;
    for(int i=1;i<=n;i++) 
    {
        b[i]+=c+(i-1)*d;
        if(b[i]>=0&&i<=m) s.insert({b[i],i});
    } 
    int res=0; int j=1;
    for(int i=1;i<=n;i++)
    {
        int r=i+m-1;
        if(r>n) break;
        int temp=pre[i-1]+post[r+1]+(int)s.size();
        res=max(res,temp);
        if(b[i]>=0)
          if(s.find({b[i],i})!=s.end()) 
             s.erase(s.find({b[i],i}));
        while(!s.empty())
        {
            int temp=(*s.begin()).first;
            if(temp-j*d<0) s.erase(s.begin());
            else break; 
        }
        j++; 
        if(a[r]+c+(m-1)*d>=0) s.insert({b[r],r});
    }
    if(res>=k) return 1;
return 0;
}
void solve() {
    cin>>n>>k>>m>>c>>d;;
    for(int i=1;i<=n;i++) cin>>a[i];
    int l=0; int r=1e18;
    while(l<r)
    {
        int mid=(l+r+1)>>1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    cout<<l<<endl;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7660kb

input:

6 4 3 1 2
1 1 4 5 1 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7628kb

input:

7 3 2 4 0
1 9 1 9 8 1 0

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7828kb

input:

8 3 5 0 0
2 0 2 2 1 2 1 8

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1160ms
memory: 22628kb

input:

200000 200000 100000 0 1000000000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: -100
Wrong Answer
time: 208ms
memory: 14836kb

input:

200000 1 100000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

1000000000000000000

result:

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