Submission #871065

#TimeUsernameProblemLanguageResultExecution timeMemory
871065Ahmed57Weirdtree (RMI21_weirdtree)C++17
0 / 100
7 ms5996 KiB
#include <bits/stdc++.h> using namespace std; long long arr[10001],n; void initialise(int N, int Q,int h[]){ n = N; for(int i = 1;i<=n;i++){ arr[i] = h[i]; } } void cut(int l, int r, int k){ vector<int> v; for(int i = l;i<=r;i++){ v.push_back(arr[i]); } sort(v.begin(),v.end()); vector<int> xd; int all = 0; for(int i = v.size()-1;i>=0;i--){ all+=v[i]; xd.push_back(all); } reverse(xd.begin(),xd.end()); int nah = 0; for(int i = v.size()-1;i>=0;i--){ if(i&&v[i]==v[i-1])continue; int elem = v.size()-i; if(k-(xd[i]-(elem*v[i]))>=0){ nah = i; } } int elem = v.size()-nah; long long num = v[nah]-((k-(xd[nah]-(elem*v[nah])))/elem); long long rem = k-num; for(int i = l;i<=r;i++){ arr[i] = min(arr[i],num); if(arr[i]==num&&rem&&arr[i]!=0){ arr[i]--; rem--; } } } void magic(int i, int x){ arr[i] = x; } long long int inspect(int l, int r){ long long sum = 0; for(int i = l;i<=r;i++){ sum+=arr[i]; } return sum; } /* signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); initialise(6,1,{0,1,2,3,1,2,3}); cut(1,6,3); cout<<inspect(1,6)<<endl; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...