Submission #548347

#TimeUsernameProblemLanguageResultExecution timeMemory
548347PherokungSnowball (JOI21_ho_t2)C++14
100 / 100
108 ms15420 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second typedef pair<ll,ll> pa; ll n,q,x[200005],a,mx=0,mi=0,sum=0,ans=0,val[200005][2]; priority_queue<pa,vector<pa>,greater<pa> > pq; int main(){ scanf("%lld%lld",&n,&q); for(int i=1;i<=n;i++) scanf("%lld",&x[i]); for(int i=1;i<=n-1;i++) pq.push({x[i+1]-x[i],i}); memset(val,-1,sizeof val); for(int i=1;i<=q;i++){ scanf("%lld",&a); sum += a; if(sum < mi){ while(!pq.empty()){ if(abs(sum) + mx >= pq.top().F){ val[pq.top().S][1] = mx; val[pq.top().S+1][0] = pq.top().F - mx; // printf("?? %d (%d)= %d, %d (%d)= %d\n",pq.top().S,1,mx,pq.top().S+1,0,pq.top().F-mx); pq.pop(); } else break; } mi = sum; } if(sum > mx){ while(!pq.empty()){ if(abs(sum) + abs(mi) >= pq.top().F){ val[pq.top().S+1][0] = abs(mi); val[pq.top().S][1] = pq.top().F - abs(mi); pq.pop(); } else break; } mx = sum; } } for(int i=1;i<=n;i++){ if(i != 1 && val[i][0] == -1) val[i][0] = abs(mi); if(i != n && val[i][1] == -1) val[i][1] = mx; } val[1][0] = -mi, val[n][1] = mx; for(int i=1;i<=n;i++) printf("%lld\n",val[i][0] + val[i][1]); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%lld%lld",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:11:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
      |                        ~~~~~^~~~~~~~~~~~~~
Main.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lld",&a);
      |   ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...