Mai intai trebuie sa te autentifici.
Cod sursa(job #2068196)
Utilizator | Data | 17 noiembrie 2017 12:58:15 | |
---|---|---|---|
Problema | Transport | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.75 kb |
#include <cstdio> // 60
#define MAXN 16000
#define MAX 999999
using namespace std;
int v[MAXN + 5], n;
int sepoate( int cost ) {
int aux, r, i;
r = 0;
aux = cost;
for( i = 1; i <= n; i++ ) {
if( v[i] > cost )
return MAX;
if( aux >= v[i] )
aux -= v[i];
else {
aux = cost;
r++;
i--;
}
}
return r;
}
int main( ) {
int k, i, r, pas;
freopen( "transport.in", "r", stdin );
freopen( "transport.out", "w", stdout );
scanf( "%d%d", &n, &k );
for( i = 1; i <= n; i++ )
scanf( "%d", &v[i] );
pas = 1 << 30;
r = 0;
while( pas != 0 ) {
if( sepoate( r + pas ) >= k )
r += pas;
pas /= 2;
}
printf( "%d", r + 1 );
return 0;
}