Submission #372618

#TimeUsernameProblemLanguageResultExecution timeMemory
372618blueSnowball (JOI21_ho_t2)C++11
100 / 100
281 ms11500 KiB
#include <iostream> #include <vector> using namespace std; int main() { int N, Q; cin >> N >> Q; long long X[N+1]; for(int i = 1; i <= N; i++) cin >> X[i]; long long W[Q+1]; for(int i = 1; i <= Q; i++) cin >> W[i]; long long Wsum[Q+1]; Wsum[0] = 0; for(int i = 1; i <= Q; i++) Wsum[i] = Wsum[i-1] + W[i]; // for(long long i = 0; i <= Q; i++) cout << Wsum[i] << ' '; // cout << '\n'; long long Wmin[Q+1], Wmax[Q+1]; Wmin[0] = Wmax[0] = 0; for(int i = 1; i <= Q; i++) { Wmin[i] = min(Wsum[i], Wmin[i-1]); Wmax[i] = max(Wsum[i], Wmax[i-1]); } // for(long long i = 0; i <= Q; i++) cout << Wmin[i] << ' '; // cout << '\n'; // for(long long i = 0; i <= Q; i++) cout << Wmax[i] << ' '; // cout << '\n'; vector<long long> res(N+1, 0); res[1] += -Wmin[Q]; for(int i = 1; i < N; i++) { int A = 0; for(int bit = 20; bit >= 0; bit--) { if(A + (1 << bit) > Q) continue; if(-Wmin[A + (1 << bit)] + Wmax[A + (1 << bit)] < X[i+1] - X[i]) A += (1 << bit); } A++; // cout << A << ' '; if(A == Q+1) { res[i] += Wmax[Q]; res[i+1] += -Wmin[Q]; } else { if(W[A] < 0) { res[i] += Wmax[A-1]; res[i+1] += X[i+1] - X[i] - Wmax[A-1]; } else { res[i+1] += -Wmin[A-1]; res[i] += X[i+1] - X[i] - (-Wmin[A-1]); } } } // cout << '\n'; res[N] += Wmax[Q]; for(int i = 1; i <= N; i++) cout << res[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...