Please read the new rule regarding the restriction on the use of AI tools. ×

PLS HELP I HAVE NOT SLEPT FOR 2 days but can't find solution

Revision en1, by GreedyXploit, 2020-09-19 10:54:02

QUESTION LINK

    #include<iostream>
    #include<algorithm>
    #include<vector>
    using namespace std;
     
    int main()
    {
        long long n ; //floors
        long long m ; //letters
     
        cin>>n;
        cin>>m;
        long long total = 0;
        vector<long long >a;
        for(long long  i = 0 ; i<n;i++)
        {
            long long k;
            cin>>k;
            total += k;
            a.push_back(total);
        }
     
        //cin>>m;
        vector<long long>b;
        for(int i = 0 ; i<m;i++)
        {
            long long k ;
            cin>>k;
            b.push_back(k);
        }
        
        for(long long  i = 0 ; i<m ; i++)
        {
            long long letter = b[i];
            auto f = lower_bound(a.begin() , a.end() , letter) - a.begin();
            vector<long long>c;
            long long  j = (f == 0)?1:a[f-1];
            while(j<=a[f])
            {
                c.push_back(j);
                ++j;
            }
            auto r = lower_bound(c.begin() , c.end() , letter) - c.begin();
            if(letter<=10)
            cout<<f+1<<" "<<r+1<<"\n";
            else
            cout<<f+1<<" "<<r<<"\n";
        }
    }
     

THIS IS MY code but it is having MEMORY LIMIT EXCEEDED

pls guys give a detailed solution code.And also say what is wrong in my code

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English GreedyXploit 2020-09-19 10:54:02 1524 Initial revision (published)