Submission #464820

# Submission time Handle Problem Language Result Execution time Memory
464820 2021-08-14T09:25:14 Z Alen777 Fountain (eJOI20_fountain) C++14
60 / 100
1016 ms 524292 KB
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

#define ll long long
#define ull unsigned ll
#define pb push_back
#define mpr make_pair
#define lb lower_bound
#define ld long double
#define ub upper_bound

const int N = 100005;
int c[N], d[N];
vector<ll> s;
vector<pair<long long, int> > cnt[N];

void solve() {
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> d[i] >> c[i];
    }
    bool flag = true;
    for (int i = 0; i < n - 1; i++) {
        if (d[i] >= d[i + 1]) {
            flag = false;
            break;
        }
    }
    if (flag) {
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            sum += c[i];
            s.push_back(sum);
        }
        while (q--) {
            int ind;
            ll tar;
            cin >> ind >> tar;
            ind--;
            if (ind != 0) {
                tar += s[ind - 1];
            }
            int ind0 = lower_bound(s.begin(), s.end(), tar) - s.begin();
            if (ind0 == n) {
                cout << 0 << endl;
                continue;
            }
            cout << ind0 + 1 << endl;
        }
        return;
    }
    for (int i = 0; i < n; i++) {
        cnt[i].push_back(mpr(c[i], i));
        int ind = i;
        long long tar = c[i];
        for (int j = i + 1; j < n; j++) {
            if (d[j] > d[ind]) {
                tar += c[j];
                ind = j;
                cnt[i].push_back(mpr(tar, ind));
            }
        }
    }
    while (q--) {
        int ind;
        long long tar;
        cin >> ind >> tar;
        ind--;
        int ind0 = lower_bound(cnt[ind].begin(), cnt[ind].end(), mpr(tar, 0)) - cnt[ind].begin();
        if (ind0 == cnt[ind].size()) {
            cout << 0 << endl;
            continue;
        }
        cout << cnt[ind][ind0].second + 1 << endl;
    }
}

int main() {
    /*cout.setf(ios::fixed | ios::showpoint);
    cout.precision(6);*/
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Compilation message

fountain.cpp: In function 'void solve()':
fountain.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         if (ind0 == cnt[ind].size()) {
      |             ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 4 ms 2892 KB Output is correct
3 Correct 4 ms 2892 KB Output is correct
4 Correct 5 ms 3020 KB Output is correct
5 Correct 6 ms 2652 KB Output is correct
6 Correct 12 ms 6732 KB Output is correct
7 Correct 6 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 7896 KB Output is correct
2 Correct 316 ms 8112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 4 ms 2892 KB Output is correct
3 Correct 4 ms 2892 KB Output is correct
4 Correct 5 ms 3020 KB Output is correct
5 Correct 6 ms 2652 KB Output is correct
6 Correct 12 ms 6732 KB Output is correct
7 Correct 6 ms 2636 KB Output is correct
8 Correct 292 ms 7896 KB Output is correct
9 Correct 316 ms 8112 KB Output is correct
10 Correct 7 ms 2764 KB Output is correct
11 Runtime error 1016 ms 524292 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -