➤ Problem Link : 474B. Worms
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; int main() { int n,x; cin>>n; int val=0; int pile=1; map<int,int> mp; for(int i=0;i<n;i++) { cin>>x; for(int j=1;j<=x;j++) mp[j+val]=pile; val+=x; pile++; } int m; cin>>m; while(m--) { cin>>x; cout<<mp[x]<<"\n"; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!