Submission #465274

# Submission time Handle Problem Language Result Execution time Memory
465274 2021-08-15T13:08:56 Z CyberCow Fountain (eJOI20_fountain) C++17
60 / 100
98 ms 5236 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
using namespace std;
using ll = long long;
int d[100005], c[100005], pref[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q, i, j;
    cin >> n >> q;
    for ( i = 0; i < n; i++)
    {
        cin >> d[i] >> c[i];
    }
    if (n <= 1000)
    {
        for (i = 0; i < q; i++)
        {
            int x, y;
            cin >> x >> y;
            x--;
            j = x;
            y -= c[j];
            int g = 1;
            while (j >= 0 && y > 0)
            {
                int h = j + 1;
                while (h < n && d[j] >= d[h])
                {
                    h++;
                }
                if (h >= n)
                {
                    g = 0;
                    break;
                }
                j = h;
                y -= c[j];
            }
            if (g)
                cout << j + 1 << '\n';
            else
                cout << 0 << '\n';
        }
    }
    else
    {
        pref[1] = c[0];
        for ( i = 1; i < n; i++)
        {
            pref[i + 1] = pref[i] + c[i];
        }
        pref[n] = 1000000000;
        for ( i = 0; i < q; i++)
        {
            int x, y;
            cin >> x >> y;
            int ind = lower_bound(pref + 1, pref + n + 2, pref[x - 1] + y) - pref;
            if (ind == n)
                cout << 0 << '\n';
            else
                cout << ind << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 3612 KB Output is correct
2 Correct 98 ms 5236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 78 ms 3612 KB Output is correct
9 Correct 98 ms 5236 KB Output is correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Halted 0 ms 0 KB -