-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollege_Life_4.cpp
More file actions
67 lines (63 loc) · 1.67 KB
/
College_Life_4.cpp
File metadata and controls
67 lines (63 loc) · 1.67 KB
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
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
#define m1 1000000007
#define int long long
#define float double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define mid(l, r) (l + (r - l) / 2)
#define loop(i, a, b) for(int i = (a); i<= (b); i++)
#define loopneg(i, a, b) for(int i = (a); i>= (b); i--)
#define arll(n) long long ar[n]
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int32_t main(){
fast
int t=1;
cin>>t;
while(t--){
int n, e, h, a, b, c, index1, index2, o, k, i;
cin>>n>>e>>h>>a>>b>>c;
vector<int>v;
vector<int>v1;
for(i=0;i<=n+1;i++){
v1.pb(i);
}
for(i=0; i<=n; i++){
index1=lower_bound(v1.begin(), v1.end(), (2*n-e-2*i))-v1.begin();
index2=upper_bound(v1.begin(), v1.end(), (h-3*i))-v1.begin()-1;
if(index2<index1||index1==n+1){
continue;
}
if(index2==n+1&&index2+3*i>h){
continue;
}
if(c>a){
k=(index1<(n-i)?index1 : (n-i));
}
else{
k=(index2<(n-i)?index2:(n-i));
}
o=n-k-i;
if(k+2*i>=2*n-e&&k+3*i<=h){
v.pb(a*o+b*i+c*k);
}
}
if(v.size()==0){
cout<<"-1"<<endl;
}
else
{
int min=v[0];
for(int j=0; j<v.size();j++){
if(v[j]<min){
min=v[j];
}
}
cout<<min<<endl;
}
}
}