using namespace std; int main()
{ //freopen("sale.inp","w",stdin); //freopen("sale.out","r",stdout); vector <int> b; vector <int> vt;int n,x,k;int S=0; cin>>n>>k; for(int i=0;i<n;i++) { cin>>x; vt.push_back(x);} S=vt[0]; for(int i=1;i<n;i++) { for(int j=0;j<i;j++) { if(vt[j]<vt[i]) b.push_back(vt[j]);} sort(b.begin(),b.end()); if(b.size()>=k) {S=S+b[k-1];} if(b.size()<k) {S=S+vt[i];} b.clear(); } cout<<S; return 0; }
This comment is hidden due to too much negative feedback. Click here to view it.
Comments
This comment is hidden due to too much negative feedback. Click here to view it.