有L个苹果和香蕉排成一条直线,其中有N个香蕉,你可以使用至多M次魔法道具将香蕉变成苹果,最后“最长的连续苹果数量”即为你本次苹果消消乐的得分。
给定苹果和香蕉的排列,求你能获得的最大得分。
输入
第一行是3个整数N、M和L,表示香蕉的数量,魔法道具使用次数,以及苹果和香蕉的总数。
第二行包含N个整数a1, a2, … aN(1 <= a1 < a2 < … < aN<= L),表示第a1, a2, … aN个位置上摆放的是香蕉,其余位置摆放的都是苹果。
输出
输出通过使用魔法道具后你能获得的最大得分。
样例输入
5 2 100
10 30 55 56 90
样例输出
59
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 10;
int n,m,l,ans;
int mp[maxn];
signed main(){
ios::sync_with_stdio(0);
cin >> n >> m >> l;
for(int i = 1; i <= n; i++)
cin >> mp[i];
mp[0] = 0;
mp[n + 1] = l + 1;
int l = 1,r = m;
while(r <= n){
ans = max(ans,mp[r + 1] - mp[l - 1] + 1 - 2);
l++;
r++;
}
cout << ans << endl;
return 0;
}
原文链接: https://www.cnblogs.com/hazelxcf/p/12301594.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/192064
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!