Submission #282893

#TimeUsernameProblemLanguageResultExecution timeMemory
282893arnold518방벽 (JOI15_walls)C++14
10 / 100
3083 ms1536 KiB
#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)

walls.cpp: In function 'int main()':
walls.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
walls.cpp:17:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
walls.cpp:18:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  for(int i=1; i<=M; i++) scanf("%d", &B[i]);
      |                          ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...