Submission #101864

#TimeUsernameProblemLanguageResultExecution timeMemory
101864rocketninja7Safety (NOI18_safety)C++14
100 / 100
405 ms20600 KiB
#include <cstdio> #include <vector> #include <set> using namespace std; int main(){ int N; long long int H; scanf("%d%lld", &N, &H); long long int S[N+1]; for(int i=1;i<N+1;i++){ scanf("%lld", &S[i]); } multiset<long long int> pointsL; multiset<long long int> pointsR; pointsL.insert(-1); pointsR.insert(1000000001); long long int ans=0; for(int i=1;i<N+1;i++){ if(S[i]<*(--pointsL.end())-H*i){ pointsL.insert(S[i]+H*i); pointsL.insert(S[i]+H*i); pointsR.insert((*(--pointsL.end()))-2*H*i); pointsL.erase(--pointsL.end()); ans+=(*pointsR.begin())+H*i-S[i]; } else if(S[i]>*pointsR.begin()+H*i){ pointsR.insert(S[i]-H*i); pointsR.insert(S[i]-H*i); pointsL.insert((*pointsR.begin())+2*H*i); pointsR.erase(pointsR.begin()); ans+=S[i]-(*(--pointsL.end()))+H*i; } else{ pointsL.insert(S[i]+H*i); pointsR.insert(S[i]-H*i); } } printf("%lld", ans); return 0; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%lld", &N, &H);
     ~~~~~^~~~~~~~~~~~~~~~~~
safety.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &S[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...