# Codeforces Round #621 (Div. 1 + Div. 2) 题解

A. Cow and Haybales

```#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<iostream>
using namespace std;
ll s=0,w=1;
char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)w=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘) s=s*10+ch-‘0‘,ch=getchar();
return s*w;
}
const int manx=1e5+5;
ll a[manx];
int main()
{
while(kk--)
{
ll n,m;
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++) cin>>a[i];
ll kkk=0;
for(int i=2;i<=n;i++){
if(!a[i]) continue;
if(m>=(i-1)){
ll res=m/(i-1);
if(a[i]<res) m-=a[i]*(i-1),kkk+=a[i];
else m%=(i-1),kkk+=res;
}
else break;
}
cout<<a[1]+kkk<<endl;
}

return 0;
}```
View Code

B. Cow and Friend

```#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int main()
{
int yy;
cin>>yy;
while(yy--){
int n,x;
scanf("%d%d",&n,&x);
int k=0,fla=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]<=x){
k=max(a[i],k);
}
if(a[i]>x){
fla=1;
}
}
if(fla&&k!=x){
cout<<2<<endl;
continue;
}
if(!(x%k)) cout<<x/k<<endl;
else cout<<(x/k+1)<<endl;
}
}```
View Code

C. Cow and Message

```#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define maxn 100010
ll letter[maxn][30],vis[30][30],hz[30]={0},cnt[30]={0};
int main()
{
memset(vis,0, sizeof(vis));
memset(letter,0, sizeof(letter));
string s;
cin>>s;
int n=s.length();
for (int i = 0; i <n ; ++i) {
if(i>0){
for (int j = 0; j <26 ; ++j) {
letter[i][j]=letter[i-1][j];
}
}
letter[i][s[i]-‘a‘]++;
cnt[s[i]-‘a‘]++;
}
for (int k = 0; k <n-1 ; ++k) {
for (int i = 0; i <26 ; ++i) {
hz[i]=letter[n-1][i]-letter[k][i];
vis[s[k]-‘a‘][i]+=hz[i];
}
}
ll kk=0;
for (int l = 0; l <26 ; ++l) {
for (int i = 0; i <26 ; ++i) {
if(vis[l][i]>kk) kk=vis[l][i];
}
}
for (int m = 0; m <26 ; ++m) {
if(cnt[m]>kk) kk=cnt[m];
}
cout<<kk<<endl;
return 0;
}```
View Code

Codeforces Round #621 (Div. 1 + Div. 2) 题解

(0)
(0)