Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:65777216")
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <stack>
- #include <map>
- #include <queue>
- #include <string>
- #include <memory.h>
- #include <iterator>
- #define y1 trololoy1
- #define y0 trololoy0
- #define mem(A,X) memset(A,X,sizeof(A))
- #define memo(A) memset(A,0,sizeof(A))
- #define forn(I,B) for (int I=1;I<=(B);I++)
- #define forg(H,V) for (int H=first[V];h;h=next[H])
- #define rep(I,B) for (int I=0;I<(B);I++)
- #define labs(X) (((X)>0)?(X):(-(X)))
- #define ropen(X) freopen(X,"r",stdin)
- #define wopen(X) freopen(X,"w",stdout)
- #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
- #define pb push_back
- #define mp make_pair
- #define all(X) (X).begin(),(X).end()
- #define sqr(X) ((X)*(X))
- using namespace std;
- typedef pair <int,int> pii;
- typedef double ld;
- typedef long long ll;
- typedef pair <ll,ll> pll;
- typedef vector<int> vi;
- const int N=111111;
- const int INF=111111111;
- const double eps=1e-9;
- const double pi=3.14159265358979;
- int d[1001][1001],n,m,a[N],b[1001];
- inline bool check(int k){
- int ans=0;
- forn(i,1000) for (int j=i+1;j<=1000;j++) if (b[i] && b[j] && d[i][j]>=k) ++ans;
- return ans<=m;
- }
- int main(){
- scanf("%d%d",&n,&m);
- mem(d,63);
- forn(i,n){
- scanf("%d",&a[i]);
- b[a[i]]=1;
- }
- forn(i,n) forn(j,i-1){
- int l=a[i],r=a[j];
- if (l>r) swap(l,r);
- d[l][r]=min(d[l][r],i-j-1);
- }
- forn(k,n-2){
- if (check(k)){
- printf("%d\n",k);
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment