

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
#define N 500000
#define ll long long
using namespace std;
ll a[N+2], s[N+2];
int posmin[N+2];
ll p;
int n, res = -1, posi, posj;
int main()
{
freopen("dish.inp","r",stdin);
freopen("dish.out","w",stdout);
cin >> n >> p;
for (int i=1; i<=n; i++) cin >> a[i];
ll smin = 0;
for (int i=1; i<=n; i++)
{
s[i] = s[i-1] + a[i];
if (s[posmin[i-1]] > s[i]) posmin[i] = i;
else posmin[i] = posmin[i-1];
}
int jj = n;
for (int i=n; i>=0; i--)
if (i == posmin[i])
{
int j;
for (j = jj; j >= i; j--)
if (s[j] - s[i] >= p)
{
if (res < j - i)
{
res = j - i;
posi = i;
posj = j;
}
break;
}
jj = j;
}
if (res == -1) cout << -1;
else cout << posi+1 << " " << posj;
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?

Bảng tin
0
612
0
3/20 test