Skip to content

Instantly share code, notes, and snippets.

@Vicfred
Created February 24, 2014 09:52
Show Gist options
  • Save Vicfred/9184801 to your computer and use it in GitHub Desktop.
Save Vicfred/9184801 to your computer and use it in GitHub Desktop.
2534 - Arrow Flips
//http://coj.uci.cu/24h/problem.xhtml?abb=2534
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int main() {
int T, K;
int inicio, fin, k, maxima, window;
char S[100005];
scanf("%d", &T);
while(T--) {
scanf("%d %s", &K, S);
maxima = 0;
window = 0; inicio = 0; fin = 0; k = 0;
while(fin < (int)strlen(S)) {
if(S[fin] == '>') {
window++; fin++;
if(window > maxima) maxima = window;
}
else {
if(k < K) {
k++; window++; fin++;
if(window > maxima) maxima = window;
} else {
if(S[inicio] == '<') {
k--;
window--;
inicio++;
} else {
window--;
inicio++;
}
}
}
}
window = 0; inicio = 0; fin = 0; k = 0;
while(fin < (int)strlen(S)) {
if(S[fin] == '<') {
window++; fin++;
if(window > maxima) maxima = window;
}
else {
if(k < K) {
k++; window++; fin++;
if(window > maxima) maxima = window;
} else {
if(S[inicio] == '>') {
k--;
window--;
inicio++;
} else {
window--;
inicio++;
}
}
}
}
printf("%d\n", maxima);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment