str = "wbwbwwbwbwbw"*100 w,b = [int(x) for x ininput().split()] sm = [] sm.append(0) cnt = 0 for x instr: if x == 'w': cnt+=1 sm.append(cnt) for l inrange(1,len(sm)): r = l+w+b-1 if r >= len(sm): break if(sm[r] -sm[l-1]==w): print("Yes") exit(0) print('No')
n = int(input()) string = input() string = ' ' + string a = [int(x) for x ininput().split()] sm = [0] for x in a: sm.append(sm[-1]+x) a = [0] + a cost = [0]*(n+5) for i inrange(1,n+1): cost[i]=cost[i-1] if (string[i] == '1')^(i%2) : cost[i]+=a[i] ans = int(1e18) for i inrange(1,n): ans = min(ans,cost[i]+(sm[n]-sm[i])-(cost[n]-cost[i])) ans = min(ans,(sm[i]-cost[i])+(cost[n]-cost[i])) print(ans)
n = int(input()) string = input() string = ' ' + string a = [int(x) for x ininput().split()] a = [0] + a cost1 = [0]*(n+5) cost2 = [0]*(n+5) for i inrange(1,n+1): cost1[i]=cost1[i-1] cost2[i]=cost2[i-1] if (string[i] == '1')^(i%2) : cost1[i] += a[i] else : cost2[i] += a[i] ans = int(1e18) for i inrange(1,n): ans = min(ans,cost1[i]+cost2[n]-cost2[i]) ans = min(ans,cost2[i]+cost1[n]-cost1[i]) print(ans)
n,m,q = [int(x) for x ininput().split()] ope = [] for _ inrange(q): t,a,x = [int(x) for x ininput().split()] ope.append((t,a,x)) sm = n * m color = [0]*(int(2e5+5)) col = [0]*(int(2e5+5)) colsum,rowsum = 0,0 row = [0]*(int(2e5+5)) for t,a,x in ope[::-1]: if t == 1: if row[a] == 0: rowsum += 1 color[x] += m - colsum sm -= m - colsum row[a] = 1 else: if col[a] == 0: colsum += 1 color[x] += n - rowsum sm -= n - rowsum col[a] = 1 color[0]+=sm ans = [] for i inrange(int(2e5+2)): if(color[i] != 0): ans.append((i,color[i])) print(len(ans)) for a,b in ans: print(a,b,end=" ") print()
#include<bits/stdc++.h> usingnamespace std; #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define int long long #define rep(i,l,r) for(int i = l;i<=r;i++) #define per(i,r,l) for(int i = r;i>=l;i--) constint INF = 0x3f3f3f3f3f3f3f3f; typedef pair<int,int> PII; int N; int n; string S,T; constint maxn = 1e5+5; int cnt[26][maxn]; vector<int> pos[26]; boolcheck(int k){ int used = 0;//已经用了多少套完整的S int p = 0;//目前这一套用到哪了 for(char ch : T){ int kk = k;//还需要多少个kk int num = ch-'a'; if(cnt[num][n] == 0){returnfalse;} int time = min(cnt[num][n]-cnt[num][p],kk); kk -= time; p = pos[num][cnt[num][p]+time]; used += kk/cnt[num][n]; kk -= kk/cnt[num][n] * cnt[num][n]; if(kk){ used++; p = pos[num][kk]; } if(used + (p!=0) > N){ //如果p不等于0表示有一套S用了一半。这时候需要让答案加一 returnfalse; } } returntrue; } voidsolve(){ cin>>N>>S>>T; n = S.length(); S = " "+ S; for(int i = 0;i<26;i++) pos[i].push_back(0); for(int i =1;i<=n;i++){ for(int j = 0;j<26;j++){ cnt[j][i] += cnt[j][i-1]; } cnt[S[i]-'a'][i]++; pos[S[i]-'a'].push_back(i); } int l = 0,r = 1e18; while(l < r){ int mid = (l+r+1)/2; if(check(mid)) l = mid; else r = mid -1; } cout<<l; } signedmain(){ int T = 1; // cin>>T; while(T--){ solve(); } return0; }