Submission #841826

#TimeUsernameProblemLanguageResultExecution timeMemory
841826konberFountain (eJOI20_fountain)C++14
60 / 100
70 ms5460 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...