【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D】Single-use Stones
Codeforces div use round single
2023-09-14 09:03:44 时间
【链接】 我是链接,点我呀:)
【题意】
【题解】
设长度为L的所有区间里面,石头的个数的最小值为k 设取到k的区间为l,r那么k就为最多能通过的青蛙个数。
假设k再大一点。比如为k+1
那么所有的k+1只青蛙,
肯定会在某个时刻都落在l,r这个长度为L的区间
(无法直接跳过这个区间)
但是这个区间只有k个石头。
所以k+1只肯定有一只无法通过。
所以最多只能为k只青蛙。
然后再考虑方案问题
因为我们k获取的方式。
所以每个长度为l的区间都至少有k个石头。
那么这k只青蛙显然每次跳都可以不用重复踩石头通过。
(第i只青蛙一开始跳到第i个石头上,然后接下来,每次都跳到接下来的第k个石头上,这样就不会重复走石头了)
所以这k只青蛙都能到另外一边,且k是最大的。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 1e5;
int w,l,a[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> w >> l;
rep1(i,1,w-1){
cin >> a[i];
a[i]+=a[i-1];
}
a[w]+=a[w-1]+1;
//x[i+k]-x[i]<=l
//i
int ans = 1e9+7;
for (int i = l;i<w;i++){
ans = min(ans,a[i]-a[i-l]);
}
cout<<ans<<endl;
return 0;
}
相关文章
- 【Codeforces Round #696 (Div. 2) C】Array Destruction
- 【Codeforces 924C】Riverside Curio
- 【Codeforces 1091D】New Year and the Permutation Concatenation
- 【 Codeforces Round #519 by Botan Investments B】Lost Array
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
- 【Codeforces Round #453 (Div. 2) C】 Hashing Trees
- 【Codeforces Round #185 (Div. 2) B】Archer
- 【19.27%】【codeforces 618D】Hamiltonian Spanning Tree
- 【23.33%】【codeforces 664C】International Olympiad
- 【30.49%】【codeforces 569A】Music
- 【codeforces 527D】Clique Problem
- 【codeforces 750B】New Year and North Pole
- 【codeforces 798C】Mike and gcd problem
- 【codeforces 709B】Checkpoints
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
- 【codeforces 429D】Tricky Function
- 【codeforces 799B】T-shirt buying
- CodeForces 462B Appleman and Card Game(贪心)
- Codeforces Round #254 (Div. 2)D(预计)
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard
- CodeForces Round #257 (Div. 2)
- Codeforces Round #107 (Div. 2)---A. Soft Drinking
- Codeforces Round #446 (Div. 2)
- Codeforces Round #417 (Div. 2) 花式被虐