Pagini recente » Cod sursa (job #1439027) | Cod sursa (job #1872388) | Cod sursa (job #711717) | Cod sursa (job #1538384) | Cod sursa (job #1701756)
#include <bits/stdc++.h>
const int DIM = 1 << 5;
using namespace std;
int N, C; long long S, W[DIM], power, answer;
struct str{ int x, y, z; } V[DIM];
inline bool cmp( str A, str B ) {
return A.x > B.x;
}
int main () {
FILE *input_file = fopen( "shop.in" , "r" );
FILE *output_file = fopen( "shop.out", "w" );
fscanf( input_file, "%d %d %lld", &N, &C, &S );
for( int i = 1; i <= N; i ++ ) {
fscanf( input_file, "%d %d", &V[i].x, &V[i].y );
V[i].z = i;
}
sort( V + 1, V + N + 1, cmp );
for( int i = 1; i <= N; i ++ ) {
power = 1;
for( int j = 1; j <= V[i].x; j ++ )
power *= C;
W[ V[i].z ] = min( S / power, V[i].y * 1LL );
S -= W[ V[i].z ] * power; answer += W[ V[i].z ];
}
fprintf( output_file, "%lld\n", answer );
for( int i = 1; i <= N; i ++ )
fprintf( output_file, "%d ", W[i] );
return 0;
}