# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105712 | Pro_ktmr | 방벽 (JOI15_walls) | C++14 | 3089 ms | 3820 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;
#define LL long long
#define MP(a,b) make_pair(a,b)
int N,M;
int A[200000],B[200000];
vector<int> P;
int main(){
cin >> N >> M;
for(int i=0; i<N; i++){
cin >> A[i] >> B[i];
}
int tmp = 0;
for(int i=0; i<M; i++){
int p;
cin >> p;
if(tmp == 0){
if(P.size() > 0){
if(P.back() < p) tmp = 1;
if(P.back() > p) tmp = -1;
}
P.push_back(p);
}
else if(tmp == 1){
if(P.back() <= p) P.back() = p;
else{
tmp = -1;
P.push_back(p);
}
}
else{
if(P.back() >= p) P.back() = p;
else{
tmp = 1;
P.push_back(p);
}
}
}
for(int i=0; i<N; i++){
LL ans = 0;
int a = A[i];
int b = B[i];
for(int j=0; j<P.size(); j++){
if(P[j] > b){
int tmp = P[j] - b;
ans += tmp;
b += tmp;
a += tmp;
}
if(P[j] < a){
int tmp = a - P[j];
ans += tmp;
b -= tmp;
a -= tmp;
}
}
cout << ans << endl;
}
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... |