# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
282893 | arnold518 | 방벽 (JOI15_walls) | C++14 | 3083 ms | 1536 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
int N, M;
pii A[MAXN+10];
int B[MAXN+10], C[MAXN+10];
int main()
{
scanf("%d%d", &N, &M);
for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
for(int i=1; i<=M; i++) scanf("%d", &B[i]);
for(int j=1; j<=N; j++)
{
ll ans=0;
int l=A[j].first, r=A[j].second;
for(int i=1; i<=M; i++)
{
if(l<=B[i] && B[i]<=r) continue;
else if(B[i]<l)
{
int t=l-B[i];
ans+=t; l-=t; r-=t;
}
else if(B[i]>r)
{
int t=B[i]-r;
ans+=t; l+=t; r+=t;
}
}
ans=0;
for(int i=M; i>=1; i--)
{
if(l<=B[i] && B[i]<=r) continue;
else if(B[i]<l)
{
int t=l-B[i];
ans+=t; l-=t; r-=t;
}
else if(B[i]>r)
{
int t=B[i]-r;
ans+=t; l+=t; r+=t;
}
}
ans+=abs(l-A[j].first);
printf("%lld\n", ans);
}
}
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... |