Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<long> autumnLeaves(vector<int> leaves, int percentage, vector<int> day, vector<int> starting, vector<int> ending) {
- #define ll long long
- int n = (int)leaves.size();
- int q = (int)day.size();
- vector<vector<ll>> fallen(65, vector<ll>(n+2));
- for(int i=1;i<=63;i++) {
- for(int j=0;j<n;j++) {
- int reduction = ceil(leaves[j] * (percentage / 100.0)) + 0.1;
- fallen[i][j+1] = fallen[i][j] + reduction;
- leaves[j] -= reduction;
- }
- }
- vector<long> ans(q);
- for(int i=0;i<q;i++)
- if (day[i] > 63)
- ans[i] = 0;
- else
- ans[i] = fallen[day[i]][ending[i]] - fallen[day[i]][starting[i] - 1];
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement