int main() { int test_cases; cin>>test_cases; ll N, D, H, M; string s; REP(ttt, test_cases) { cin>>N; vector<PII> w; REP(i, N) { cin>>D>>H>>M; REP(j, H) w.PB(MP(M+j, D)); } sort(ALL(w)); ll ft = w[0].first * (360 + 360-w[0].second); ll st = w[1].first * (360-w[1].second); ll ans = st>=ft ? 1 : 0; cout<<"Case #"<<ttt+1<<": "<<ans<<endl; } return 0; }
(追記)
int main() { int test_cases; cin>>test_cases; ll N, D, H, M; string s; REP(ttt, test_cases) { cin>>N; priority_queue<pair<ll, pair<ll, ll>>> q; ll all = 0; REP(i, N) { cin>>D>>H>>M; REP(j, H) q.push(MP(-(M+j)*(360-D), MP(-1, (M+j)*360))); all+=H; } ll ans = 1LL<<60; ll cur=all; while(q.size() && cur < all*2) { ll t = -q.top().first; ll dn = q.top().second.first; ll dur = q.top().second.second; q.pop(); cur+=dn; q.push(MP(-(t+dur), MP(1, dur))); if(t != -q.top().first) { ans = min(ans, cur); } } ans = min(ans, cur); cout<<"Case #"<<ttt+1<<": "<<ans<<endl; } return 0; }