# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
668419 |
2022-12-03T20:18:52 Z |
600Mihnea |
Safety (NOI18_safety) |
C++17 |
|
2000 ms |
644 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#endif // ONPC
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
int n, dmax, sol = 0;
cin >> n >> dmax;
vector<int> a, b;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (i == 0)
{
a.push_back(x);
b.push_back(x);
continue;
}
for (auto &it : a)
{
it -= dmax;
}
for (auto &it : b)
{
it += dmax;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
sol += abs(a.back() - x);
if (x <= a.back())
{
b.push_back(a.back());
a.pop_back();
a.push_back(x);
a.push_back(x);
}
else
{
if (x >= b[0])
{
a.push_back(b[0]);
reverse(b.begin(), b.end());
b.pop_back();
b.push_back(x);
b.push_back(x);
}
else
{
a.push_back(x);
b.push_back(x);
}
}
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2078 ms |
644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |