# Java ```java import java.util.*; public class Main { public static void main(String[] args) throws Exception { // Your code here! Scanner sc = new Scanner(System.in); // 座席数 int seatNum = sc.nextInt(); // グループ数 int groupNum = sc.nextInt(); // 答え(座れた人数) int answer = 0; // 座席リスト(0: 空いてる, 1: 空いてない) ArrayList<Integer> seatList = new ArrayList<>(); for (int i = 0; i < seatNum; i++) { // seatListを0で埋める seatList.add(0); } // グループの人数分ループする for (int i = 0; i < groupNum; i++) { // 人数 int num = sc.nextInt(); // 座りたい場所 int seatIndex = sc.nextInt() - 1; boolean isEmpty = true; // 席が空いているか確認 for (int j = 0; j < num; j++) { // 座席リストに1があったら空いてない // -> isEmpty を false にする if (seatList.get((seatIndex + j) % seatNum) == 1) { isEmpty = false; } } // isEmpty が true だったら if (isEmpty) { // 指定の座席を1にする for (int j = 0; j < num; j++) { seatList.set((seatIndex + j) % seatNum, 1); // 座れた人数を増やす answer ++; } } } // 答えを出力 System.out.println(answer); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up