daolao,26分求调
查看原帖
daolao,26分求调
1105630
220218SZC楼主2024/7/13 16:51
#include<bits/stdc++.h>
using namespace std;
#define zd 500005
typedef long long ll;
ll a,b,c[zd],d,e[zd],g=1; 
int main()
{
cin>>a>>b;
for(int i=1;i<=a;i++){
	cin>>c[i];
}
e[1]=c[1];
for(int i=2;i<=b;i++){
	ll l=0;
	for(int j=g;j<=a;j++){
		ll h=0;
		for(int k=1;k<=i-1;k++){
			if(c[j]==e[k]){
				h=1;
				break;
			}
		}
		if(h==0){
			l=1;
			d+=j-i;
			g=j+1;
			break;
		}
	}
	if(l==0){
		cout<<-1;
		return 0;
	}
}
cout<<d;
return 0;
}
2024/7/13 16:51
加载中...