- #include <bits/stdc++.h>
- using namespace std;
- long long int revenue(vector<int> a, int k)
- {
- vector<long long int> arr(k+1,0);
- long long int temp2=0;
- long long int temp;
- for(int i=a.size()-1;i>=0;i--)
- {
- temp = arr[k-1];
- for(int j=k;j>=0;j--)
- {
- if(j==0) arr[j] = temp2;
- else arr[j] = max(a[i]+arr[j-1],temp2);
- }
- temp2 = max(a[i]+temp,temp2);
- }
- return temp2;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n,k;
- cin>>n>>k;
- vector<int> a(n);
- for(int i=0;i<n;i++) cin>>a[i];
- cout<<revenue(a,k);
- }
[text] billboards
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: