--- title: "餐厅" created: 2025-11-28 tags: - 算法 --- # 餐厅 ## 题目 [餐厅](https://www.acwing.com/problem/content/description/5388/) ![[image-a62eda3f.png]] ## 思路分析 ![[image-576ca0f8.png]] ## 代码实现 ```cpp #include using namespace std; #define endl '\n' typedef long long LL; const int N=2e5+10; LL s[N]; int n,q; int find(LL sum){ int l=0,r=n; while(l>1; if(s[m]<=sum) l=m; else r=m-1; } return n-r; } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>q; for(int i=1;i<=n;i++){ int x;cin>>x; s[i]=s[i-1]+x; } LL sum=0; while(q--){ LL x;cin>>x; sum+=x; if(sum>=s[n]) sum=0; cout<