-
Notifications
You must be signed in to change notification settings - Fork 0
/
College-Life-4.cpp
59 lines (43 loc) · 1.21 KB
/
College-Life-4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// https://www.codechef.com/MARCH21C/problems/COLGLF4
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class dish{
public:
int p;
};
void solution() {
long long int i, N, E, CH, flag = 0, ans = -1, val1, val2, K;
dish d[3];
cin >> N >> E >> CH >> d[0].p >> d[1].p >> d[2].p;
vector<long long int> temp;
for ( i = 0; i <= N+1; i++) temp.push_back(i);
for ( i = 0; i <= N ; i++) {
val2 = upper_bound(temp.begin(), temp.end(), (CH-3*i)) - temp.begin() - 1;
if (val2 == N+1 && val2+3*i>CH) continue;
val1 = lower_bound(temp.begin(), temp.end(), (2*N - E - 2*i)) - temp.begin();
if (val2<val1 || val1 == N+1) continue;
if (d[2].p>d[0].p) K = (val1<(N-i)?val1:(N-i));
else K = (val2<(N-i)?val2:(N-i));
if (((K+2*i)>=(2*N-E)) && (K+3*i)<=CH) {
long long int t = d[0].p*(N-K-i) + d[1].p*i + d[2].p*K;
if (flag == 0) ans = t;
else {
if (ans > t ) ans = t;
}
flag = 1;
}
}
if (flag == 0) ans = -1;
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long int test;
cin >> test;
while (test--) solution();
return 0;
}