Skip to content

Commit a27d152

Browse files
authored
Create 2019-G-C.cpp
1 parent 91aeb25 commit a27d152

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Diff for: kick-start/2019-G-C.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include<bits/stdc++.h>
2+
#define ms(x,v) memset((x),v,sizeof(x))
3+
#define INF 0x3f3f3f3f
4+
using namespace std;
5+
6+
const int MAXN = 100+10;
7+
typedef long long LL;
8+
9+
LL N,H;
10+
11+
pair<LL,LL> val[MAXN];
12+
LL sa[MAXN],sb[MAXN];
13+
LL ans;
14+
LL pow3[MAXN];
15+
void dfs(LL v1,LL v2,int idx){//0,...,N-1
16+
17+
if(v1 >= H && v2 >=H){
18+
ans += pow3[N-idx];
19+
return;
20+
}
21+
if(idx >= N)return;
22+
if(v1 + sa[N-idx] < H || v2 + sb[N-idx] < H)return;
23+
dfs(v1 + val[idx].first,v2,idx+1);
24+
dfs(v1,v2+val[idx].second,idx+1);
25+
dfs(v1+val[idx].first,v2 + val[idx].second,idx+1);
26+
}
27+
28+
29+
void solve(){
30+
cin >> N >> H;
31+
for(int i=0 ; i<N ; ++i)cin >> val[i].first;
32+
for(int i=0 ; i<N ; ++i)cin >> val[i].second;
33+
sort(val,val+N,greater<pair<LL,LL> >());
34+
sa[0] =0;
35+
sb[0] = 0;
36+
for(int i = N-1 ; i>=0 ; --i){
37+
sa[N-i] = sa[N-i -1] + val[i].first;
38+
sb[N-i] = sb[N-i - 1] + val[i].second;
39+
}
40+
ans =0;
41+
dfs(0,0,0);
42+
cout << ans << "\n";
43+
}
44+
45+
46+
47+
48+
49+
int main(){
50+
ios :: sync_with_stdio(0);
51+
cin.tie(0);
52+
// cout.tie(0);
53+
std::cout.precision(10);
54+
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
55+
pow3[0] =1;
56+
for(int i=1 ; i<=20;++i)pow3[i] = pow3[i-1] * 3;
57+
int T;
58+
cin >> T;
59+
for(int tt =1 ; tt <=T ; ++tt)
60+
{
61+
cout << "Case #" << tt << ": ";
62+
solve();
63+
}
64+
65+
66+
return 0;
67+
}

0 commit comments

Comments
 (0)