D-游游的k-好数组_牛客周赛 Round 6 (nowcoder.com)(关键--a[1]=a[k+1])
cpp
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100005;
int a[N];
typedef pair<int,int>PII;
PII b[N];
void solve(){
int n,k,x;
cin>>n>>k>>x;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i%k].first=0;
b[i%k].second=0;
}
for(int i=1;i<=n;i++){
b[i%k].first=max(a[i],b[i%k].first);
b[i%k].second++;
}
for(int i=1;i<=n;i++){
x-=b[i%k].first-a[i];
}
if(x<0){
cout<<-1<<endl;
return;
}
sort(b,b+k);
int ma=-1;
for(int i=k-1;i>=0;i--){
if(b[i].second!=0&&ma==-1)ma=b[i].first;
if(b[i].second<=x&&b[i].second>0){
ma=max(ma,b[i].first+x/b[i].second);
}
}
cout<<ma<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
using namespace std;
const int N=200005;
int a[N];
typedef pair<int,int>PII;
bool vis[N];
int cnt[27];
char s[N],t[N];
int n,k;
void dfs(int u){
vis[u]=true;
cnt[s[u]-'a']--;
cnt[t[u]-'a']++;
if(u-k>=1&&!vis[u-k])dfs(u-k);
if(u-(k+1)>=1&&!vis[u-(k+1)])dfs(u-(k+1));
if(u+k<=n&&!vis[u+k])dfs(u+k);
if(u+k+1<=n&&!vis[u+k+1])dfs(u+k+1);
}
void solve(){
cin>>n>>k;
cin>> (s+1) >> (t+1) ;
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++){
if(!vis[i]){
memset(cnt,0,sizeof(cnt));
dfs(i);
for(int i=0;i<26;i++){
if(cnt[i]!=0){
cout<<"NO"<<endl;
return;
}
}
}
}
cout<<"YES"<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}