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
| #include <bits/stdc++.h> #define ll long long #define int long long #define Orz ios::sync_with_stdio(0),cin.tie(0) #define N 51 #define FOR(i,n) for(int i=0;i<n;i++) #define pii pair<int,int> #define pid pair<int,double> #define pdi pair<double,int> using namespace std; int n,m;
void solve(){ priority_queue<int,vector<int>,greater<>>pq; cin>>n>>m; int ans=0,time=0; for(int i=1;i<=n;i++){ cin>>time; if(i>m){ time+=pq.top(); pq.pop(); } pq.push(time); ans = max(ans,time); } cout<<ans<<endl; }
signed main(){ Orz; int t=1; while(t--){ solve(); } }
|