| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1357454 | Aviansh | Safety (NOI18_safety) | C++20 | 30 ms | 3684 KiB |
#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
long long h;
cin >> n >> h;
long long ans = 0;
priority_queue<long long>pql;
priority_queue<long long, vector<long long>, greater<long long>>pqr;
long long c;
cin >> c;
pql.push(c);
pqr.push(c);
long long lazl=-h;
long long lazr=h;
for(int i = 1;i<n;i++){
cin >> c;
if(pql.top()+lazl>=c){
///put in left
ans+=pql.top()+lazl-c;
pql.push(c-lazl);
pql.push(c-lazl);
long long curr = pql.top()+lazl;
pql.pop();
pqr.push(curr-lazr);
}
else if(pqr.top()+lazr<=c){
///put in right
ans+=c-pqr.top()-lazr;
pqr.push(c-lazr);
pqr.push(c-lazr);
long long curr = pqr.top()+lazr;
pqr.pop();
pql.push(curr-lazl);
}
else{
pql.push(c-lazl);
pqr.push(c-lazr);
}
lazl-=h;
lazr+=h;
}
cout << ans;
return 0;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
