DontCallMeNuttoPleas

CreateTime

Apr 14th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     int time,n;
  5.     cin >> time >> n;
  6.     int safe[n+1],wayot[time+1];
  7.     for(int i=1;i<=n;i++){
  8.         cin >> safe[i];
  9.     }
  10.     wayot[0]=0;
  11.     for(int i=1;i<=time;i++){
  12.         int mx=-2e9;
  13.         for(int j=1;j<=n;j++){
  14.             if(j<=i){
  15.                 if(mx<safe[j]+wayot[i-j])
  16.                     mx=safe[j]+wayot[i-j];
  17.                 wayot[i]=mx;
  18.             }
  19.         }
  20.     }
  21.     printf("%d",wayot[time]);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment