-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcowflix.cpp
More file actions
38 lines (38 loc) · 784 Bytes
/
cowflix.cpp
File metadata and controls
38 lines (38 loc) · 784 Bytes
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
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int n, size=1, arr[1001], digits[1001], counter=0, target, maxx=-1;
void gen(int index, int lastindex){
if(index==size){
int total=0;
for(int i=0; i<size; i++){
total+=arr[i];
}
if(total>maxx and total<=target){
maxx=total;
}
return;
}
else{
for(int i=lastindex; i<n; i++){
arr[index]=digits[i];
gen(index+1, i+1);
}
}
return;
}
int main(){
cin >> target >> n;
for(int i=0; i<n; i++){
cin >> digits[i];
}
for(int i=0; i<n; i++){
size=i+1;
gen(0,0);
}
cout << maxx << endl;
return 0;
}