Submission #676508

#TimeUsernameProblemLanguageResultExecution timeMemory
676508numberesSafety (NOI18_safety)C++17
18 / 100
52 ms6124 KiB
/** * @date 2022-12-31 10:53:37 * @author numberes * 煮不在乎.RAmen! * https://oj.uz/problem/view/NOI18_safety */ #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> #define ll long long using namespace std; priority_queue<ll> l; priority_queue<ll,vector<ll>,greater<ll> > r; int ls,rs; int n,h,s[200005]; int main(){ ls=rs=0; scanf("%d %d",&n,&h); ll res=0; for(int i=1;i<=n;i++){ scanf("%d",&s[i]); if(i==1){ l.push(s[i]); r.push(s[i]); continue; } ls-=h;rs+=h; if(s[i]<l.top()+ls){ l.push(s[i]-ls); l.push(s[i]-ls); r.push(l.top()+ls-rs); res+=l.top()+ls-s[i]; l.pop(); } else if(s[i]>r.top()+rs){ r.push(s[i]-rs); r.push(s[i]-rs); l.push(r.top()+rs-ls); res+=s[i]-r.top()-rs; r.pop(); } else{ l.push(s[i]-ls); r.push(s[i]-rs); } } printf("%lld\n",res); return 0; }

Compilation message (stderr)

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