丢手绢
code:
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define eps 1e-6
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
ll n, m;
int a[maxn], res = 0, sum;
void work()
{
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i], sum += a[i];
int l = 1, r = 1, ans = 0;
while(l <= n)
{
//一个点离其他点的最远距离一定是在总距离的一半的两边
while(res < sum / 2){
if(r > n) r = 1;
res += a[r];
++r;
}
ans = max(ans, min(res, sum - res));
res -= a[l];
++l;
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(0);
// int TT;cin>>TT;while(TT--)
work();
return 0;
}
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define eps 1e-6
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 1e9 + 7;
ll n, m;
int a[30], cnt = 0;
void work()
{
string s;cin >> s;
n = s.size();
int l = 0, r = 0, ans = 1e6;
while(l < n)
{
while(cnt < 26 && r < n){// 先找到一个从l开始满足条件的子串
int x = s[r] - 'a';
if(!a[x]) ++cnt;
a[x]++;
++r;
}
if(cnt == 26) ans = min(ans, r - l);// 只要满足条件就更新
a[s[l] - 'a']--;// 左指针右移,删去不包含的
if(!a[s[l]-'a']) --cnt;
++l;// 右移试图缩小满足条件的子串长度
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(0);
// int TT;cin>>TT;while(TT--)
work();
return 0;
}