#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 = 1; 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 = 1; vector AsaAC; for(ll j = 0; j < 6; j++) { string t; ll d; cin >> t >> d; if(Solved[t] >= order - N && Solved[t] > 0) d = min(d, K); time_sum += d; if(time_sum > 60 && ok) { cout << j << endl; ok = 0; } AsaAC.push_back(t); } if(ok) cout << 6 << endl; for(string t : AsaAC) { Solved[t]=order; order++; } } } }