Created
February 17, 2016 12:13
-
-
Save hanjae-jea/6ba2a927f870e2ae0f99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class test { | |
static int n,m; | |
static int uniqueIntegerCount = 0; | |
static int answer = 0; | |
static int[] cnt = new int[10000001]; | |
static Deque deque = new ArrayDeque<>(); | |
static void insert(int num) | |
{ | |
deque.addLast(num); | |
cnt[num]++; | |
if( cnt[num] == 1 ) | |
uniqueIntegerCount++; | |
} | |
static void remove(int index) | |
{ | |
// if Subsequence does not fulled. | |
if( index < m ) return; | |
int num = (int)deque.pollFirst(); | |
cnt[num] --; | |
if( cnt[num] == 0 ) | |
uniqueIntegerCount--; | |
} | |
static void update() | |
{ | |
if( answer < uniqueIntegerCount ) | |
answer = uniqueIntegerCount; | |
} | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
n = in.nextInt(); | |
m = in.nextInt(); | |
for (int i = 0; i < n; i++) { | |
int num = in.nextInt(); | |
insert(num); | |
remove(i); | |
update(); | |
} | |
System.out.println(answer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment