Submission #841826

# Submission time Handle Problem Language Result Execution time Memory
841826 2023-09-02T07:00:59 Z konber Fountain (eJOI20_fountain) C++14
60 / 100
70 ms 5460 KB
#include <iostream>
#include <vector>

using namespace std;

vector<int> pref_sum;

int prefix_sum(int a, int b){
    return pref_sum[b] - pref_sum[a-1];
}

int main()
{
    //freopen("data.in", "r", stdin);
    int N, Q, r, c, last, i;
    scanf("%d%d", &N, &Q);
    int d[N+1], v[N+1];
    pref_sum.resize(N+1, 0);
    bool order=true;
    for(int j=1; j <= N; j++){
        scanf("%d%d", &d[j], &v[j]);
        pref_sum[j] = pref_sum[j-1] + v[j];
        if(j>1 && d[j] <= d[j-1]) order=false;
    }

    if (N <= 1000 && Q <= 2000){
        while(Q--){
            scanf("%d%d", &r, &c);
            last = r;
            c -= v[r];
            for(i=r; i <= N && c > 0; i++){
                if(d[i] > d[last]){
                    c -= v[i];
                    last = i;
                }
            }
            printf("%d\n", (c <= 0) ? last : 0);
        }
    }
    else if(order){
        while(Q--){
            scanf("%d%d", &r, &c);
            int first=r, last=N, mid, ans=0;
            while(first <= last){
                mid = (first+last)/2;
                if(prefix_sum(r, mid) >= c){
                    ans=mid;
                    last=mid-1;
                }
                else first = mid+1;
            }
            printf("%d\n", ans);
        }
    }
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d", &N, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~
fountain.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d%d", &d[j], &v[j]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:28:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |             scanf("%d%d", &r, &c);
      |             ~~~~~^~~~~~~~~~~~~~~~
fountain.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d%d", &r, &c);
      |             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 3664 KB Output is correct
2 Correct 70 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 59 ms 3664 KB Output is correct
9 Correct 70 ms 5460 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -