Submission #384336

#TimeUsernameProblemLanguageResultExecution timeMemory
384336patrikpavic2Bigger segments (IZhO19_segments)C++17
37 / 100
1592 ms3684 KiB
#include <cstdio> #include <vector> #include <algorithm> #define X first #define Y second #define PB push_back using namespace std; typedef long long ll; const int N = 5e5 + 500; int A[N], n, dp[N]; ll P[N]; vector < pair < pair < ll, ll > , int > > pri; int main(){ scanf("%d", &n); for(int i = 0;i < n;i++){ scanf("%d", A + i); P[i] = A[i] + (i ? P[i - 1] : 0LL); } pri.PB({{0, 0}, 0}); for(int i = 0;i < n;i++){ int naj = 0; for(int j = 1;j < (int)pri.size();j++) if(P[i] >= pri[j].X.X && pri[j].X.Y > pri[naj].X.Y) naj = j; dp[i] = pri[naj].Y + 1; pri.PB({{2LL * P[i] - pri[naj].X.Y, P[i]}, dp[i]}); } printf("%d\n", dp[n - 1]); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
segments.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |   scanf("%d", 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...