Click Here to go back to the homepage.

Hanging Out on the Terrace Solution:



import java.util.*;


public class woo {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	
		String[] line = sc.nextLine().split(" ");
		int limit = Integer.parseInt(line[0]);
		int groups = Integer.parseInt(line[1]);
		int people = 0;
		int bad = 0;
		for(int i = 0; i < groups; i++){
			String[] curr = sc.nextLine().split(" ");
			int multiplier = curr[0].equals("enter")? 1:-1;
			if(multiplier * Integer.parseInt(curr[1]) + people <= limit)
				people += multiplier * Integer.parseInt(curr[1]);
			else{
				bad++;
			}
		}
		System.out.println(bad);
	
	
	}
	

}