-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuestion 4.cpp
More file actions
46 lines (42 loc) · 930 Bytes
/
Question 4.cpp
File metadata and controls
46 lines (42 loc) · 930 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
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
int res(int*x , int *r , int n , int M) {
int table[M+1];
table[0] = 0;
int j = 0;
for ( int i = 1 ; i <= M; i++) {
if( j < n) {
if( x[j] != i) {
table[i] = table[i-1];
}
else {
if ( i <=5) {
table[i] = max(table[i-1] , r[j]);
}
else {
table[i] = max(r[j] + table[i - 6] , table[i-1]);
}
j++;
}
}
else {
table[i] = table[i-1];
}
}
return table[M];
}
int main() {
int M , n;
cout << "\nEnter M\t:\t";
cin >> M;
cout << "\nEnter n\t:\t";
cin >> n;
for ( int i = 0; i < n; i++ {
cin >> x[i];
}
for ( int i = 0; i < n; i++ {
cin >> r[i];
}
cout << res( x , r , n , M);
return 0;
}