Submission #964242

#TimeUsernameProblemLanguageResultExecution timeMemory
964242guechotjrhhSafety (NOI18_safety)C++14
100 / 100
194 ms21864 KiB
#include<stdio.h> #include<vector> #pragma warning (disable:4996) using namespace std; #include<algorithm> #include<iostream> #include<set> #define ll long long ll ab(ll n) { return n > 0 ? n : -n; } int inf = 1e9; long long func(int n, int h, vector<int> s) { multiset<ll> lef = { 0 }, rig = { inf }; ll pl = 0, pr = 0; //real xElef is x+pl ll val = 0; for (int i = 0; i < n; i++) { pr += h; pl -= h; if (s[i] <= *rig.begin()+pr && s[i] >= *prev(lef.end())+pl) { lef.insert(s[i] - pl); rig.insert(s[i] - pr); } else if (s[i] > *rig.begin() + pr) { int u = *rig.begin() + pr; rig.erase(rig.begin()); val += s[i] - u; lef.insert(u - pl); rig.insert(s[i] - pr); rig.insert(s[i] - pr); } else { int u = *prev(lef.end()) + pl; val += u - s[i]; lef.erase(prev(lef.end())); lef.insert(s[i] - pl); lef.insert(s[i] - pl); rig.insert(u - pr); } } return val; } int main() { int N, H; scanf("%d%d", &N, &H); vector<int> S(N); for (int i = 0; i < N; i++) scanf("%d", &S[i]); long long ans = func(N, H, move(S)); printf("%lld\n", ans); }

Compilation message (stderr)

safety.cpp:3: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    3 | #pragma warning (disable:4996)
      | 
safety.cpp: In function 'int main()':
safety.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &N, &H);
      |  ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:48:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  for (int i = 0; i < N; i++) scanf("%d", &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...