# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
668418 |
2022-12-03T20:17:42 Z |
600Mihnea |
Safety (NOI18_safety) |
C++17 |
|
2000 ms |
716 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());
if (x <= a.back())
{
sol += a.back() - x;
b.push_back(a.back());
a.pop_back();
a.push_back(x);
a.push_back(x);
}
else
{
if (x >= b[0])
{
if (1)
{
sol += 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);
}
}
assert((int) a.size() == i + 1);
assert((int) b.size() == i + 1);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
continue;
cout << " ---> ";
for (auto &it : a)
{
cout << it << " ";
}
cout << " and ";
for (auto &it : b)
{
cout << it << " ";
}
cout << "\n";
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
636 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
212 KB |
Output is correct |
14 |
Correct |
8 ms |
336 KB |
Output is correct |
15 |
Correct |
7 ms |
324 KB |
Output is correct |
16 |
Correct |
7 ms |
212 KB |
Output is correct |
17 |
Correct |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
212 KB |
Output is correct |
19 |
Correct |
7 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
212 KB |
Output is correct |
14 |
Correct |
8 ms |
336 KB |
Output is correct |
15 |
Correct |
7 ms |
324 KB |
Output is correct |
16 |
Correct |
7 ms |
212 KB |
Output is correct |
17 |
Correct |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
212 KB |
Output is correct |
19 |
Correct |
7 ms |
212 KB |
Output is correct |
20 |
Correct |
6 ms |
212 KB |
Output is correct |
21 |
Correct |
7 ms |
212 KB |
Output is correct |
22 |
Correct |
5 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
6 ms |
328 KB |
Output is correct |
25 |
Correct |
5 ms |
212 KB |
Output is correct |
26 |
Correct |
6 ms |
212 KB |
Output is correct |
27 |
Correct |
7 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
212 KB |
Output is correct |
14 |
Correct |
8 ms |
336 KB |
Output is correct |
15 |
Correct |
7 ms |
324 KB |
Output is correct |
16 |
Correct |
7 ms |
212 KB |
Output is correct |
17 |
Correct |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
212 KB |
Output is correct |
19 |
Correct |
7 ms |
212 KB |
Output is correct |
20 |
Correct |
6 ms |
212 KB |
Output is correct |
21 |
Correct |
7 ms |
212 KB |
Output is correct |
22 |
Correct |
5 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
6 ms |
328 KB |
Output is correct |
25 |
Correct |
5 ms |
212 KB |
Output is correct |
26 |
Correct |
6 ms |
212 KB |
Output is correct |
27 |
Correct |
7 ms |
212 KB |
Output is correct |
28 |
Correct |
1004 ms |
464 KB |
Output is correct |
29 |
Correct |
806 ms |
412 KB |
Output is correct |
30 |
Correct |
928 ms |
464 KB |
Output is correct |
31 |
Correct |
705 ms |
484 KB |
Output is correct |
32 |
Correct |
710 ms |
504 KB |
Output is correct |
33 |
Correct |
825 ms |
716 KB |
Output is correct |
34 |
Correct |
1063 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
6 ms |
212 KB |
Output is correct |
20 |
Correct |
8 ms |
336 KB |
Output is correct |
21 |
Correct |
7 ms |
324 KB |
Output is correct |
22 |
Correct |
7 ms |
212 KB |
Output is correct |
23 |
Correct |
6 ms |
212 KB |
Output is correct |
24 |
Correct |
4 ms |
212 KB |
Output is correct |
25 |
Correct |
7 ms |
212 KB |
Output is correct |
26 |
Correct |
6 ms |
212 KB |
Output is correct |
27 |
Correct |
7 ms |
212 KB |
Output is correct |
28 |
Correct |
5 ms |
212 KB |
Output is correct |
29 |
Correct |
5 ms |
212 KB |
Output is correct |
30 |
Correct |
6 ms |
328 KB |
Output is correct |
31 |
Correct |
5 ms |
212 KB |
Output is correct |
32 |
Correct |
6 ms |
212 KB |
Output is correct |
33 |
Correct |
7 ms |
212 KB |
Output is correct |
34 |
Correct |
1004 ms |
464 KB |
Output is correct |
35 |
Correct |
806 ms |
412 KB |
Output is correct |
36 |
Correct |
928 ms |
464 KB |
Output is correct |
37 |
Correct |
705 ms |
484 KB |
Output is correct |
38 |
Correct |
710 ms |
504 KB |
Output is correct |
39 |
Correct |
825 ms |
716 KB |
Output is correct |
40 |
Correct |
1063 ms |
620 KB |
Output is correct |
41 |
Correct |
1094 ms |
580 KB |
Output is correct |
42 |
Correct |
600 ms |
340 KB |
Output is correct |
43 |
Correct |
931 ms |
532 KB |
Output is correct |
44 |
Correct |
892 ms |
460 KB |
Output is correct |
45 |
Correct |
886 ms |
564 KB |
Output is correct |
46 |
Correct |
755 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Execution timed out |
2083 ms |
636 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |