UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205571#2637. Wilczedrdilyor1003618ms46780kbC++111.0kb2024-07-18 17:56:512024-07-18 20:03:30

answer

/**
	Author: 丘成桐(囯内)
**/
#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
int n,p,d;
int a[2000005];
//选择 d 的区间.
int pre[2000005];
//[j,j+d-1]
int pp[2000005];
bool check(int x){
	deque<int> q;
	for(int i=1;i<=x-d+1;i++){
		while(!q.empty()&&q.back()<pp[i])q.pop_back();
		q.push_back(pp[i]);
	}
	if(pre[x]-q.front()<=p)return 1;
	for(int i=2;i<=n-x+1;i++){
		int cur=pre[i+x-1]-pre[i-1];
		while(!q.empty()&&q.back()<pp[i+x-d])q.pop_back();
		q.push_back(pp[i+x-d]);
		if(q.front()==pp[i-1])q.pop_front();
		cur-=q.front();
		if(cur<=p)return 1;
		//选择里面和最大的.
		//
	}
	return 0;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>p>>d;
	for(int i=1;i<=n;i++)cin>>a[i],pre[i]=pre[i-1]+a[i];
	for(int i=1;i<=n-d+1;i++)pp[i]=pre[i+d-1]-pre[i-1];
	int l=d,r=n;
	int res=-1;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){res=mid,l=mid+1;}
		else r=mid-1;
	}
	cout<<res<<"\n";
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1292kb

input:

1000 140500 31
635 1326 1342 1116 355 1397 813 590 550 533 626 875 1221 225 1112 196 1160 192 25 374...

output:

243

result:

ok single line: '243'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1288kb

input:

1000 121200 20
351 27 24 621 239 639 415 21 541 120 499 1135 815 778 1026 995 267 1203 536 1004 1029...

output:

245

result:

ok single line: '245'

Test #3:

score: 10
Accepted
time: 779ms
memory: 46780kb

input:

2000000 22780000 177658
2124 1846 653 233 898 205 1611 695 439 1310 19 1365 2046 196 554 107 28 935 ...

output:

197970

result:

ok single line: '197970'

Test #4:

score: 10
Accepted
time: 382ms
memory: 40872kb

input:

2000000 90850000 934907
8508 586 2151 7172 1953 7096 6147 8127 5666 7500 8586 3579 5135 1501 6375 27...

output:

955225

result:

ok single line: '955225'

Test #5:

score: 10
Accepted
time: 469ms
memory: 44632kb

input:

2000000 26990000 451405
2482 935 717 2596 1413 503 799 1774 777 1928 816 115 2603 2345 558 713 752 2...

output:

471701

result:

ok single line: '471701'

Test #6:

score: 10
Accepted
time: 310ms
memory: 38736kb

input:

2000000 95060000 1208654
5701 1750 9395 2030 6950 1481 3944 5487 4118 2144 1708 185 3546 4588 5243 6...

output:

1228983

result:

ok single line: '1228983'

Test #7:

score: 10
Accepted
time: 518ms
memory: 42500kb

input:

2000000 31200000 725152
355 2582 522 690 1698 1273 581 937 147 1579 2078 3079 2620 1940 2414 997 197...

output:

745483

result:

ok single line: '745483'

Test #8:

score: 10
Accepted
time: 508ms
memory: 43404kb

input:

2000000 67340000 608003
5048 3593 1129 5525 3038 6144 880 2911 5708 3214 4966 4073 998 4101 530 6287...

output:

628339

result:

ok single line: '628339'

Test #9:

score: 10
Accepted
time: 285ms
memory: 37492kb

input:

2000000 35410000 1365252
3507 3099 2782 2614 1356 683 3102 1599 3287 1326 978 1291 380 3521 176 546 ...

output:

1385539

result:

ok single line: '1385539'

Test #10:

score: 10
Accepted
time: 367ms
memory: 41272kb

input:

2000000 71550000 881750
1732 5991 326 3423 6566 6197 5295 5489 3598 1793 3820 3149 4165 2146 3336 35...

output:

902039

result:

ok single line: '902039'