# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20234 | rubabredwan | Jousting tournament (IOI12_tournament) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int n, N, c, r;
int R;
int K[502];
int B[502], E[502];
int P[502];
int ans = -1, idx;
void inicializa( int p ){
int i;
N = n;
for( i = 0; i < p; i++ )
P[i] = K[i];
P[p] = r;
for( i = p + 1; i < n; i++ )
P[i] = K[i - 1];
}
int maxi( int i, int j ){
int ret = -1;
for( ; i <= j; i++ )
ret = max( ret, P[i] );
return ret;
}
void recorre( int i, int j, int w ){
P[i] = w;
int aux = j - i;
for( j = j + 1; j < N; j++ )
P[++i] = P[j];
N -= aux;
}
int main(){
optimizar_io
cin >> n >> c >> r;
for( int i = 0; i < n - 1; i++ )
cin >> K[i];
for( int i = 1; i <= c; i++ )
cin >> B[i] >> E[i];
for( int i = 0; i < n; i++ ){
inicializa( i );
R = i;
int tmp = 0;
for( int j = 1; j <= c; j++ ){
int winner = maxi( B[j], E[j] );
recorre( B[j], E[j], winner );
if( R >= B[j] && R <= E[j] ){
if( winner == r )
tmp++;
else
break;
}
for( R = 0; R < N; R++ )
if( P[R] == r )
break;
}
if( tmp > ans ){
ans = tmp;
idx = i;
}
}
cout << idx << "\n";
return 0;
}