萌新疑惑
  • 板块P1725 琪露诺
  • 楼主1nes
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/5/23 17:32
  • 上次更新2024/5/23 20:19:23
查看原帖
萌新疑惑
1114867
1nes楼主2024/5/23 17:32
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
using namespace std;
const int N = 2e5 + 3;
int n , l , r , a[N];
int f[N];
deque<int> q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> l >> r;
	for(int i = 0 ; i <= n ; i++)	cin >> a[i];
	q.clear();
	for(int i = 1 ; i <= n ; i++)	f[i] = -10303303;
	for(int i = l ; i <= n ; i++){
		while(q.size() && f[q.front()] <= f[i - l])	q.pop_front();
		while(q.size() && i - r > q.back())	q.pop_back();
		q.push_front(i - l);
		f[i] = f[q.back()] + a[i];
	}
	int ans = -103030300;
	for(int i = n + 1 - r ; i <= n ; i++)	ans = max(ans , f[i]);
	cout << ans;
	return 0;
} 

代码第23行第二个while里为什么是> 而不是>=

2024/5/23 17:32
加载中...