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 n,m,a[N],c[1001];
- pii t[N];
- inline bool check(int k){
- int l=1,r=k+1;
- memo(c);
- int kv=0,ans=0;
- forn(i,k+1) ++c[a[i]];
- while (r<=n){
- if (a[l]!=a[r] && c[a[l]]==1 && c[a[r]]==1) t[++kv]=pii(min(a[l],a[r]),max(a[l],a[r]));
- --c[a[l]];
- ++c[a[r+1]];
- ++l;++r;
- }
- sort(t+1,t+kv+1);
- forn(i,kv) if (t[i]!=t[i-1]) ++ans;
- return ans<=m;
- }
- int main(){
- scanf("%d%d",&n,&m);
- forn(i,n) scanf("%d",&a[i]);
- int l=1,r=n-2;
- while (l<r){
- int m=(l+r)/2;
- if (check(m)) r=m;
- else l=m+1;
- }
- if (r!=1 && check(r-1)) printf("%d\n",r-1);
- else printf("%d\n",r);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment