Submission #36998

#TimeUsernameProblemLanguageResultExecution timeMemory
36998szawinisTaxis (POI13_tak)C++14
10 / 100
1000 ms5920 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 5e5+1; int n; ll m, d, x[N]; bool check(int lim_idx) { bool ret = 0; for (int rem = 1; rem <= lim_idx; rem++) { ll curr = 0; for (int i = 1; i < rem && curr < d; i++) curr += max(x[i] - (d - curr), 0ll); for (int i = rem + 1; i <= lim_idx && curr < d; i++) curr += max(x[i] - (d - curr), 0ll); ret |= curr >= d && x[rem] >= m - curr; } return ret; } int main() { scanf("%lld %lld %d", &m, &d, &n); for(int i = 1; i <= n; i++) scanf("%lld", x+i); sort(x+1, x+n+1, greater<ll>()); int l = 1, r = n; while(l < r) { int mid = l+r >> 1; if(check(mid)) r = mid; else l = mid+1; } if(!check(l)) printf("0"); else printf("%d", l); }

Compilation message (stderr)

tak.cpp: In function 'int main()':
tak.cpp:28:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l+r >> 1;
              ^
tak.cpp:23:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %d", &m, &d, &n);
                                   ^
tak.cpp:24:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%lld", x+i);
                                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...