#include using namespace std; #define ll long long /*hi, I'm rintaro. I’m the writer of the problem.*/ int main() { //writerの確認コード //O(NQ)解法 ll N, K, Q; cin >> N >> K >> Q; deque Kishi; for(ll i = 0; i < Q; i++) { while((ll)Kishi.size() > N) Kishi.pop_front(); ll x; cin >> x; if(x == 1) { string s; cin >> s; Kishi.push_back(s); } else { deque Last=Kishi; vector d(6); vector t(6); ll time_sum = 0, ok = 1; for(ll k = 0; k < 6; k++) { cin >> t[k] >> d[k]; if(find(Last.begin(),Last.end(),t[k]) != Last.end()) d[k] = min(d[k], K); time_sum += d[k]; if(time_sum > 60 && ok) { cout << k << endl; ok = 0; } Kishi.push_back(t[k]); } if(ok) cout << 6 << endl; } } }