54142023-05-14 18:40:02kicsiboglarGladiátorok (40 pont)cpp11Time limit exceeded 36/40870ms7332 KiB
#include <iostream>
#include <vector>
#define f first
#define plus second
#include <algorithm>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<ll, ll>;
ll n, m, q, j, i, a, b;
vector <P> gl;

ll bs(ll r, ll l, ll a)
{
    if (r == l)
    {
        if (gl[r].first <= a) return r;
        else return r - 1;
    }
    ll middle = (r + l) / 2;
    if (gl[middle].first >= a) return bs(r, middle, a);
    else return bs(middle + 1, l, a);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> n >> q;
    gl.resize(n+1);
    for (i = 1; i <= n; ++i)
    {
        cin >> gl[i].f >> gl[i].plus;

    }

    sort(gl.begin() + 1, gl.end(), [](const P& a, const P& b)
        {
            return a.f < b.f;
        });
    for (i = 1; i <= n; ++i)
    {
       // gl[i].first = max(gl[i].fisrt,gl[i - 1].first);
        gl[i].plus += gl[i - 1].plus;
    }
    for (i = 1; i <= q; ++i)
    {
        cin >> a;
        if (a < gl[1].f)
        {
            cout << "0 ";
            continue;
        }
        b = bs(1, n, a);
        a += gl[b].plus;
        j = b;
        while (b<n&&a >= gl[b + 1].f)
        {
            b = bs(b+1, n, a);
            a += (gl[b].plus-gl[j].plus);
            j = b;
        }
        cout << b << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/03ms1764 KiB
2Accepted0/013ms2748 KiB
3Accepted2/23ms2172 KiB
4Accepted2/23ms2252 KiB
5Accepted2/24ms2544 KiB
6Accepted2/24ms2756 KiB
7Accepted2/24ms2708 KiB
8Accepted2/24ms2968 KiB
9Accepted2/24ms3180 KiB
10Accepted2/24ms3140 KiB
11Accepted2/213ms3520 KiB
12Accepted2/282ms6064 KiB
13Accepted2/296ms4484 KiB
14Accepted2/2184ms6264 KiB
15Accepted2/2184ms6560 KiB
16Accepted2/2185ms6772 KiB
17Accepted2/2182ms7088 KiB
18Accepted2/2118ms7092 KiB
19Accepted2/2243ms7120 KiB
20Accepted2/2245ms7332 KiB
21Time limit exceeded0/2869ms5172 KiB
22Time limit exceeded0/2870ms5160 KiB