# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
841826 | 2023-09-02T07:00:59 Z | konber | Fountain (eJOI20_fountain) | C++14 | 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
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 3664 KB | Output is correct |
2 | Correct | 70 ms | 5460 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | - |