Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1744. Can You Eat Your Favorite Candy on Your Favorite Day?
typedef long long int ll; class Solution { public: vector<bool> canEat(vector<int>& candiesCount, vector<vector<int>>& queries) { int n = candiesCount.size(); vector<ll> pre(n); pre[0] = candiesCount[0]; for (int j = 1; j < n; j ++) pre[j] = pre[j-1] + candiesCount[j]; vector<bool> ans; for (auto q : queries) { ll t = q[0], d = q[1], limit = q[2]; d ++; bool cur = false; if (pre[t] < d) cur = false; else { // 4 5 7 8 (2) ll can = ceil((double)pre[t]/(double)limit); if (can > d) { ll bef = t > 0? pre[t-1] : 0; can = ceil((double)(bef+1)/(double)limit); if (can > d) cur = false; else cur = true; } else cur = true; } ans.push_back(cur); } return ans; } };
run
|
edit
|
history
|
help
0
MinCostKStops_DFS
IndiSort
Peg Grammar Parser Grasshopper Language
PriQHotel2
BST to DLL
Insertion Sort
static_cast makes a copy
Привет Linux
2
ForwardListString2