D. Single-use Stones
Examples 1: input 10 5 0 0 1 0 2 0 0 1 0 output 3 Examples 2: input 10 3 1 1 1 1 2 1 1 1 1 output 3
Title:
w represents the width of the river, l represents the farthest distance the frog can jump, and the w-1 element in the second line represents that there are a[i] stones at the place i from the river bank, a If a stone is stepped on twice, ask how many frogs can jump across the river at most
analyze:
Because the number of frogs that can be skipped at most is determined by the minimum number of footholds, his problem is actually in [i, i+l], i∈[l,w-1], what is the minimum number of stones
Personal code:
#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define pb push_back #define dbg(x) cout<<#x<<" = "<<(x)<<endl; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>PLL; typedef pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const ll inf=0x7fffffff; const double eps=1e-8; const int maxn =1e6; const int N = 510; const ll mod=1e9+7; const ll MOD=1e9; //------ //define ll sum[maxn]; ll a[maxn]; int w,l; //solve void solve() { while(cin>>w>>l){ ll ans=inf; for(int i=1;i<w;i++){ cin>>a[i]; sum[i]=sum[i-1]+a[i]; } for(int i=l;i<=w-1;i++){ ans=min(ans,sum[i]-sum[i-l]); } cout<<ans<<endl; memset(sum,0,sizeof(sum)); } } //main int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); /* #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif */ return 0; }