

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>
using namespace std;
int main()
{
long long n,k,a[100005],d[100005];
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
d[0]=0;
for(int i=1;i<=n;i++) d[i]=d[i-1]+a[i];
long long nmax=-1e18;
for(int i=k+1;i<=n;i++)
{
nmax=max(nmax,d[i]-d[i-k]);
}
cout<<nmax;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
#include <bits/stdc++.h>
using namespace std;
long long n,k,a[100005],s[100005],maxx=0,dau,cuoi;
void solve(){
cin >> n >> k;
for (long long i=0;i<n;i++) cin >> a[i];
s[0] = a[0];
for (long long i=1;i<n-k+1;i++) s[i] = s[i-1] + a[i];
for (long long i=k;i<n-k+1;i++) s[i] = s[i-1] + a[i] - a[i-k];
maxx = s[0];
dau = 0;
cuoi = k;
for (long long i=1;i<n-k+1;i++){
if (maxx <= s[i]) maxx = s[i];
dau = i;
cuoi = k+i-1;
}
cout << maxx << endl;
}
int main()
{
solve();
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
#include <bits/stdc++.h> using namespace std; long long n,k,s,l,r,maxx=-2e9; long long a[10000009],f[1000009]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); freopen("1.inp","r",stdin); freopen("1.out","w",stdout); cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; f[i]=f[i-1]+a[i]; } for(int i=1;i<=n-k+1;i++) { maxx=max(maxx,f[i+k-1]-f[i-1]); } cout<<maxx; } Rút gọn#include <bits/stdc++.h> using namespace std; long long n,k,s,l,r,maxx=-2e9; long long a[10000009],f[1000009]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); freopen("1.inp","r",stdin); freopen("1.out","w"... xem thêm
Bảng tin
1464
18191
1143
https://thptchuyen.ntucoder.net/Problem/Details/8444 sai r :)))
2707
41698
2041
=)) Đào j ghê v
1464
18191
1143
ko t cx code nhuw oong nhung ko full nen di kiem code
1464
18191
1143
mak code trg teset nay 2 for cx dc
2707
41698
2041
Ha, đề bảo chọn k số chứ k cần k số liên tiếp á
1464
18191
1143
ak :))) đọc nhầm đề noo
2707
41698
2041
Còn bài này là liên tiếp đó
1464
18191
1143
:))) bik r :)))