拿捏的死死的!!
2024-11-11 21:35:36
发布于:广东
3阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n, k, sum = 0;
cin >> n >> k;
vector<ll> x(n), sumk(n), smax(n);
for (int i = 0; i < n; i++)
cin >> x[i];
for (int i = 0; i < k; i++)
sum += x[i];
for (int i = 0; i < n - k + 1; i++)
{
sumk[i] = sum;
(sum -= x[i]) += x[i + k];
}
smax[n - k] = sumk[n - k];
for (int i = n - k - 1; i >= 0; i--)
{
smax[i] = max(sumk[i], smax[i + 1]);
}
ll Max = -10000000000000000ll, maxi;
for (int i = 0; i <= n - k - k; i++)
{
ll m = smax[i + k] + sumk[i];
if (Max < m)
{
maxi = i;
Max = m;
}
}
cout << maxi + 1 << ' ' << maxi + k << ' ';
ll sum2 = Max - sumk[maxi];
for (int i = maxi + k; i <= n - k; i++)
if (sum2 == sumk[i])
{
cout << i + 1 << ' ' << i + k;
break;
}
cout << endl << Max;
return 0;
}
拿捏的死死的!!
这里空空如也
有帮助,赞一个