Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int time,n;
- cin >> time >> n;
- int safe[n+1],wayot[time+1];
- for(int i=1;i<=n;i++){
- cin >> safe[i];
- }
- wayot[0]=0;
- for(int i=1;i<=time;i++){
- int mx=-2e9;
- for(int j=1;j<=n;j++){
- if(j<=i){
- if(mx<safe[j]+wayot[i-j])
- mx=safe[j]+wayot[i-j];
- wayot[i]=mx;
- }
- }
- }
- printf("%d",wayot[time]);
- }
Advertisement
Add Comment
Please, Sign In to add comment