# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730438 | Skywk | Safety (NOI18_safety) | C++11 | 2049 ms | 3248 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int h;
class SlopeTrick{
private:
vector<long long> p;
long long m = 0, b = 0;
size_t N = 0;
void insert_element(int &x){
p.push_back(x);
for(int i=N; i>0; i--){
if(p[i] >= p[i-1]) break;
swap(p[i], p[i-1]);
}
N++;
}
public:
void insert(int x){
insert_element(x);
insert_element(x);
m++;
b += -x;
}
void shift(){
for(int i=0; i<N; i++){
p[i] += (i < N/2 ? -h : h);
}
b -= (long long)h * (N >> 1);
}
long long get_min(){
long long min_value = b;
for(int i=N-1; i>=N/2; i--){
min_value += p[i];
}
return min_value;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int N;
cin>> N>> h;
vector<int> a(N);
for(int i=0; i<N; i++){
cin>> a[i];
}
SlopeTrick st;
for(int i=0; i<N; i++){
st.insert(a[i]);
st.shift();
}
cout<< st.get_min();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |