CFR 644 B. Processing Queries ( Deque Implementation )
Problem - B - Codeforces
適当に queueでやってWAもらいました。
Dequeで終了時間を抑える方が合ってるそうです。
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MAXB = MAXN; const int MAXT = 1e9 + 9; const int MAXD = 1e9 + 9; typedef long long ll; int n, b; ll t[ MAXN ], d[ MAXN ]; ll ans[ MAXN ]; void solve(){ deque< ll > dq; ll lst = 0LL; for(int i = 0; i < n; ++i){ while( !dq.empty() && dq.front() <= t[ i ] ) dq.pop_front(); if( dq.size() <= b ){ ans[ i ] = max( lst, t[ i ] ) + d[ i ]; lst = ans[ i ]; dq.push_back( ans[ i ] ); } else ans[ i ] = -1; } for(int i = 0; i < n; ++i) printf("%d%c", ans[ i ], i == n - 1 ? '\n' : ' '); } int main(){ scanf("%d%d", &n, &b); for(int i = 0; i < n; ++i) scanf("%lld%lld", &t[ i ], &d[ i ]); solve(); return 0; }