Cod sursa(job #2430643)

Utilizator AndreiDeltaBalanici Andrei Daniel AndreiDelta Data 15 iunie 2019 17:55:42
Problema Cuburi2 Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
#define Dim 250009
using namespace std;
ifstream f("cuburi2.in");
ofstream g("cuburi2.out");
typedef long long ll;
ll S[Dim],x,y,N,M,ans1,ans2;

int main()
{
    f>>N>>M;
    for(int i=1;i<=N;i++)
    {
        f>>x;
        S[i]=S[i-1]+x;
    }
    for(int i=1;i<=M;i++)
    {
        f>>x>>y;
        int st=x,dr=y;
        ans1=0;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            if(S[mij-1]-S[x-1]<S[y]-S[mij-1])
            {
                st=mij+1;
                ans1=mij;
            }
            else dr=mij-1;
        }
        g<<ans1<<" "<<ans2<<'\n';
    }

    return 0;
}