CF363B 1100

题意


解析

前缀和水题,就是在所有长度为k的区间里找个最小的。

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10,M = 1e6 + 10;
int n,m,a[N];
int main(){
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        a[i] += a[i-1];
    }
    int Min = 1 << 30,pos;
    // cout << res;
    for(int i=m;i<=n;i++){
        if(Min > a[i] - a[i-m]){
            Min = a[i] - a[i-m];
            pos = i-m+1;
        }
    }
    cout << pos;
    return 0;
}
posted @ 2022-12-28 00:08  Isaac233  阅读(13)  评论(0)    收藏  举报