QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673566 | #5417. Chat Program | cabbagea | WA | 1167ms | 22512kb | C++17 | 1.6kb | 2024-10-25 00:05:46 | 2024-10-25 00:05:47 |
Judging History
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]-mid+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: 7900kb
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: 7628kb
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: 1167ms
memory: 22512kb
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: 0
Accepted
time: 159ms
memory: 19480kb
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:
100001000000000
result:
ok 1 number(s): "100001000000000"
Test #6:
score: 0
Accepted
time: 76ms
memory: 21592kb
input:
200000 1 200000 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:
200001000000000
result:
ok 1 number(s): "200001000000000"
Test #7:
score: -100
Wrong Answer
time: 968ms
memory: 15972kb
input:
200000 24420 17993 881138881 700368758 231187558 519018952 260661004 740633836 931672020 155904999 647179942 13217847 779799803 382810661 242588977 708308843 309853544 225488875 389115097 588643904 644409212 704920939 231829287 39891424 881158891 341251089 486868469 808002305 629160633 317239613 771...
output:
964473787
result:
wrong answer 1st numbers differ - expected: '964474978', found: '964473787'