Submission #5937161


Source Code Expand

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

bool solve() {
	lli n = 1;
	string s;
	if ( cin >> n );
	else return false;
	
	vcL num( 6, 0 );
	
	for (int i = 0; i < 6; ++i) {
		cin >> num[i];
	}
	
	bool a = false, b = false, c = false;
	if ( num[0] < num[3] ) a = true;
	if ( num[1] < num[4] ) b = true;
	if ( num[2] < num[5] ) c = true;
	
	lli _max = 0;
	
	if ( a and b and c ) {
		for (int i = 0; i <= n/num[0]; ++i) {
			for (int j = 0; j <= (n-i*num[0])/num[1]; ++j) {
				lli k = (n-i*num[0]-j*num[1])/num[2];
				_max = max( _max, i*(num[3]-num[0]) + j*(num[4]-num[1]) + k*(num[5]-num[2]) );
			}
		}
		n += _max;
	}
	else if ( a and b ) {
		for (int i = 0; i <= n/num[0]; ++i) {
			_max = max( _max, i*(num[3]-num[0]) + (n-i*num[0])/num[1]*(num[4]-num[1]) );
		}
		n += _max;
		n += (n/num[5])*(num[2]-num[5]);
	}
	else if ( a and c ) {
		for (int i = 0; i <= n/num[0]; ++i) {
			_max = max( _max, i*(num[3]-num[0]) + (n-i*num[0])/num[2]*(num[5]-num[2]) );
		}
		n += _max;
		n += (n/num[4])*(num[1]-num[4]);
	}
	else if ( b and c ) {
		for (int i = 0; i <= n/num[1]; ++i) {
			_max = max( _max, i*(num[4]-num[1]) + (n-i*num[1])/num[2]*(num[5]-num[2]) );
		}
		n += _max;
		n += (n/num[3])*(num[0]-num[3]);
	}
	else if ( a ) {
		n += (n/num[0])*(num[3]-num[0]);
		for (int i = 0; i <= n/num[4]; ++i) {
			_max = max( _max, i*(num[1]-num[4]) + (n-i*num[4])/num[5]*(num[2]-num[5]) );
		}
		n += _max;
	}
	else if ( b ) {
		n += (n/num[1])*(num[4]-num[1]);
		for (int i = 0; i <= n/num[3]; ++i) {
			_max = max( _max, i*(num[0]-num[3]) + (n-i*num[3])/num[5]*(num[2]-num[5]) );
		}
		n += _max;
	}
	else if ( c ) {
		n += (n/num[2])*(num[5]-num[2]);
		for (int i = 0; i <= n/num[3]; ++i) {
			_max = max( _max, i*(num[0]-num[3]) + (n-i*num[3])/num[4]*(num[1]-num[4]) );
		}
		n += _max;
	}
	else {
		for (int i = 0; i <= n/num[3]; ++i) {
			for (int j = 0; j <= (n-i*num[3])/num[4]; ++j) {
				lli k = (n-i*num[3]-j*num[4])/num[5];
				_max = max( _max, i*(num[0]-num[3]) + j*(num[1]-num[4]) + k*(num[2]-num[5]) );
			}
		}
		n += _max;
	}
	
//	cout << "max: " << _max << '\n';
	cout << n << '\n';
	
	return true;
}

int main() {
	precal();
	int t = INT_MAX;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		if ( !solve() ) break;
	}
	return 0;
}

Submission Info

Submission Time
Task D - Squirrel Merchant
User SorahISA
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2997 Byte
Status
Exec Time 132 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt
All 600 / 600 00.txt, 41.txt, 42.txt, 45.txt, 50.txt, 55.txt, 60.txt, 65.txt, 70.txt, 75.txt, 80.txt, 81.txt, 82.txt, 83.txt, 84.txt, 85.txt, 86.txt, 87.txt, 88.txt, 89.txt, 90.txt, 91.txt, 92.txt, 93.txt, 94.txt, 95.txt, a01.txt, a02.txt, a03.txt, a04.txt, a05.txt, a06.txt, a07.txt, a08.txt, a09.txt, a10.txt, a11.txt, a12.txt, a13.txt, a14.txt, a15.txt, a16.txt, a17.txt, a18.txt, a19.txt, a20.txt, a21.txt, a22.txt, a23.txt, a24.txt, a25.txt, a26.txt, a27.txt, a28.txt, a29.txt, a30.txt, a31.txt, a32.txt, a33.txt, a34.txt, a35.txt, a36.txt, a37.txt, a38.txt, a39.txt, a40.txt, s1.txt
Case Name Status Exec Time Memory
00.txt 1 ms 256 KB
41.txt 1 ms 256 KB
42.txt 1 ms 256 KB
45.txt 1 ms 256 KB
50.txt 1 ms 256 KB
55.txt 1 ms 256 KB
60.txt 1 ms 256 KB
65.txt 1 ms 256 KB
70.txt 1 ms 256 KB
75.txt 1 ms 256 KB
80.txt 1 ms 256 KB
81.txt 3 ms 256 KB
82.txt 5 ms 256 KB
83.txt 1 ms 256 KB
84.txt 1 ms 256 KB
85.txt 27 ms 256 KB
86.txt 1 ms 256 KB
87.txt 20 ms 256 KB
88.txt 1 ms 256 KB
89.txt 1 ms 256 KB
90.txt 8 ms 256 KB
91.txt 1 ms 256 KB
92.txt 1 ms 256 KB
93.txt 1 ms 256 KB
94.txt 1 ms 256 KB
95.txt 1 ms 256 KB
a01.txt 2 ms 256 KB
a02.txt 10 ms 256 KB
a03.txt 2 ms 256 KB
a04.txt 2 ms 256 KB
a05.txt 1 ms 256 KB
a06.txt 1 ms 256 KB
a07.txt 1 ms 256 KB
a08.txt 1 ms 256 KB
a09.txt 4 ms 256 KB
a10.txt 5 ms 256 KB
a11.txt 1 ms 256 KB
a12.txt 2 ms 256 KB
a13.txt 131 ms 256 KB
a14.txt 10 ms 256 KB
a15.txt 45 ms 256 KB
a16.txt 22 ms 256 KB
a17.txt 6 ms 256 KB
a18.txt 2 ms 256 KB
a19.txt 2 ms 256 KB
a20.txt 132 ms 256 KB
a21.txt 2 ms 256 KB
a22.txt 10 ms 256 KB
a23.txt 3 ms 256 KB
a24.txt 2 ms 256 KB
a25.txt 1 ms 256 KB
a26.txt 1 ms 256 KB
a27.txt 2 ms 256 KB
a28.txt 1 ms 256 KB
a29.txt 1 ms 256 KB
a30.txt 1 ms 256 KB
a31.txt 1 ms 256 KB
a32.txt 3 ms 256 KB
a33.txt 1 ms 256 KB
a34.txt 2 ms 256 KB
a35.txt 1 ms 256 KB
a36.txt 1 ms 256 KB
a37.txt 1 ms 256 KB
a38.txt 1 ms 256 KB
a39.txt 1 ms 256 KB
a40.txt 1 ms 256 KB
s1.txt 1 ms 256 KB