---
# System prepended metadata

title: 1744. Can You Eat Your Favorite Candy on Your Favorite Day?
tags: [Leetcode, Prefix Sum, Medium]

---

# 1744. Can You Eat Your Favorite Candy on Your Favorite Day?
###### tags: `Leetcode` `Medium` `Prefix Sum`
Link: https://leetcode.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day/
## 思路
要注意day是从0开始算的 所以要加1
并且需要用long存
## Code
```java=
class Solution {
    public boolean[] canEat(int[] candiesCount, int[][] queries) {
        long[] prefixSum = new long[candiesCount.length];
        prefixSum[0] = candiesCount[0];
        for(int i=1; i<candiesCount.length; i++){
            prefixSum[i] = prefixSum[i-1] + candiesCount[i];
        }
        boolean[] ans = new boolean[queries.length];
        for(int i=0; i<queries.length; i++){
            int type = queries[i][0];
            int day = queries[i][1];
            int cap = queries[i][2];
            ans[i] = day+1 <=prefixSum[type];
            if(type!=0) ans[i] &= day+1>prefixSum[type-1]/cap;
        }
        return ans;
    }
}
```