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>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e4 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
bool acc[310];
int n;
int s1[N], s2[N], s3[N];
int rm[N];
int wh[N], rmt[N], pas[N], ans[N];
int Speed(int i){
	if(rm[i]) return 1;
	if(wh[i] < 100) return s1[i];
	if(wh[i] < 200) return s2[i];
	if(wh[i] < 300) return s3[i];
	return 1e9;
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> s1[i] >> s2[i] >> s3[i];
	int m;
	cin >> m;
	int pos;
	for(int i = 0; i < m; i++){
		cin >> pos;
		acc[pos] = true;
	}
	for(int i = 1; i <= n; i++) rmt[i] = Speed(i);
	int T = 0;
	while(true){
		int del = *min_element(rmt + 1, rmt + n + 1);
		if(del > 50) break;
		for(int i = 1; i <= n; i++){
			if(rmt[i] == Speed(i)) pas[wh[i]] ++;
		}
		T += del;
		for(int i = 1; i <= n; i++){
			rmt[i] -= del;
			if(rmt[i] == 0){
				if(rm[i]) rm[i] --;
				wh[i] ++;
				if(acc[wh[i]] && rm[i] == 0){
					rm[i] += pas[wh[i]] % 20;
				}
				rmt[i] = Speed(i);
				if(wh[i] == 300) ans[i] = T;
			}
		}
	}
	for(int i = 1; i <= n; i++) cout << ans[i] << '\n';
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |