Submission #40997

#TimeUsernameProblemLanguageResultExecution timeMemory
40997yusufakeTaxis (POI13_tak)C++98
100 / 100
175 ms4580 KiB
#include<bits/stdc++.h> using namespace std; #define _ int v, int tl, int tr, int l, int r, int h #define tm (tl+tr >> 1) #define sol v+v,tl,tm,l,r,h #define sag v+v+1,tm+1,tr,l,r,h #define mp make_pair #define pb push_back #define st first #define nd second typedef long long ll; typedef pair < int , int > pp; const int mod = 1e9 + 7; const int N = 5e5 + 5; ll A[N],m,d,n,i,j,x; void fail() { cout << 0; exit(0); } int main(){ cin >> m >> d >> n; for(i=1;i<=n;i++) scanf("%lld", &A[i]); sort(A+1 , A+n+1); reverse(A+1 , A+n+1); if(A[1] < m-d) fail(); for(i=1;i<=n && A[i] >= m-d;i++){ if(A[i] < d-x) fail(); x += A[i] - max(0LL , d - x); if(x >= m) { cout << i; return 0; } } i--; x = 0; for(j=1;j<i;j++){ x += A[j] - max(0LL , d - x); } for(j=i+1;j<=n;j++){ if(A[j] < d-x) fail(); x += A[j] - max(0LL , d - x); if(x+A[i]-max(0LL,d-x) >= m) { cout << j; return 0; } } cout << 0; return 0; }

Compilation message (stderr)

tak.cpp: In function 'int main()':
tak.cpp:27:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1;i<=n;i++) scanf("%lld", &A[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...