# CFR 806 B. Dynamic Problem Scoring ( Dummy Constraints, Greedy )

Problem - B - Codeforces

The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.

O( 5000 )

```#include <bits/stdc++.h>
using namespace std;

int N;
int A[ 120 ][ 5 ];
int correct[ 5 ];

int score( int a, int p, int q ) {
if( a == -1 ) return 0;
if( 32LL * p <= q ) {
return 3000 - 3000 / 250 * a;
} else if( 16LL * p <= q ) {
return 2500 - 2500 / 250 * a;
} else if( 8LL * p <= q ) {
return 2000 - 2000 / 250 * a;
} else if( 4LL * p <= q ) {
return 1500 - 1500 / 250 * a;
} else if( 2LL * p <= q ) {
return 1000 - 1000 / 250 * a;
}
return 500 - 500 / 250 * a;
}

int calc( int p ) {
int f = 0;
for( int i = 0; i < 5; ++i ) {
if( A[ 0 ][ i ] == -1 ) {
f += score( A[ 0 ][ i ], correct[ i ], N + p )
- score( A[ 1 ][ i ], correct[ i ], N + p );
} else if( A[ 1 ][ i ] == -1 or A[ 0 ][ i ] < A[ 1 ][ i ] ) {
f += score( A[ 0 ][ i ], correct[ i ], N + p )
- score( A[ 1 ][ i ], correct[ i ], N + p );
} else {
f += score( A[ 0 ][ i ], correct[ i ] + p, N + p )
- score( A[ 1 ][ i ], correct[ i ] + p, N + p );
}
}
return f;
}

signed main() {
cin >> N;
for( int i = 0; i < N; ++i ) {
for( int j = 0; j < 5; ++j ) {
cin >> A[ i ][ j ];
correct[ j ] += A[ i ][ j ] > -1;
}
}
for( int i = 0; i <= 5000; ++i ) {
if( calc( i ) > 0 ) {
cout << i << endl;
exit( 0 );
}
}
cout << -1 << endl;
return 0;
}
```