474B Codeforces - Worms


474B Codeforces


Worms

Solution in c++

#include <iostream>

#include <vector>

using namespace std;

vector<int> vec;

int main()

{

    long long int n,sum=0,t;

    cin>>n;

    for(int i=0;i<n;i++){

        cin>>t;

        sum+=t;

        vec.push_back(sum);

    }

    cin>>n;

    for(int i=0;i<n;i++){

        cin>>t;

        if(t<=vec[0]){cout<<"1\n";continue;}

        cout<<lower_bound(vec.begin(),vec.end(),t)-vec.begin()+1<<"\n";

    }

    return 0;

}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق