# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1000630 |
2024-06-18T04:58:37 Z |
vjudge1 |
Safety (NOI18_safety) |
C++17 |
|
77 ms |
13192 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 30, MOD = 1e9 + 7;
int n,h,a[N];
multiset<int> l,r;
int addl = 0,addr = 0;
void test(){
cin >> n >> h;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
l.insert(a[1]);
r.insert(a[1]);
ll H = 0;
for(int i = 1;i <= n;i++){
int L = (*l.rbegin()) + addl,R = (*r.begin()) + addr;
if(a[i] >= L && a[i] <= R){
l.insert(a[i] - addl);
r.insert(a[i] - addr);
}else if(a[i] >R){
H += (a[i] - R);
r.erase(r.find(R - addr));
l.insert(R - addl);
r.insert(a[i] - addr);r.insert(a[i] - addr);
}else{
H += (L - a[i]);
l.erase(l.find(L - addl));
r.insert(L - addr);
l.insert(a[i] - addl);
l.insert(a[i] - addl);
}
addl -= h;
addr += h;
}
cout << H << '\n';
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int t = 1;
// cin >> t;
while(t--){
test();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
13192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |