Cod sursa(job #1760094)

Utilizator DobosDobos Paul Dobos Data 20 septembrie 2016 12:03:49
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>
typedef long long var;
const int NMAX = 30005;

using namespace std;

ifstream fin("transport.in");
ofstream fout("transport.out");

int V[NMAX],SV[NMAX],n;

int Binary(int L,int R,int x){

    int MID;
    while(L <= R){
        if(L == R)
            return L;
        MID = (L + R) / 2;
        if(SV[MID] <= x)
            L = MID;
        else
            R = MID - 1;

    }

}


int main()
{
    ios :: sync_with_stdio(false);
    fin.tie(NULL);
    int n,T,p,b;
    fin >> n >> T;
    for(int i = 1; i <= n; i++){
        fin >> V[i];
        SV[i] = SV[i - 1] + V[i];
    }
    for(int i = n + 1,j = 1; i <= 2 * n;j++, i++){

        SV[i] = SV[i - 1] + V[j];
    }
    for(int i = 1; i <= T; i++){
        fin >> p >> b;
        fout << Binary(p , 2*n , SV[p - 1] + b)  - p << "\n";

    }


    return 0;
}