#include using namespace std; #define ll long long /*hi, I'm rintaro. I’m the writer of the problem.*/ int main() { //writerの確認コード //O(N log Q)解法 ll N, K, Q, order = 0; cin >> N >> K >> Q; map Solved; for(ll i = 0; i < Q; i++) { ll x; cin >> x; if(x == 1) { string s; cin >> s; Solved[s] = order; order++; } else { ll time_sum = 0, ok = 0; for(int j = 0; j < 6; i++) { string t; ll d; cin >> t >> d; if(Solved[t] > order - N) d = min(d, K); time_sum += d; if(time_sum > 60 && ok) { cout << j << endl; ok = 0; } Solved[t] = order; order++; } if(ok) cout << 6 << endl; } } }