UVA – 10050 – Hartals

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int T = in.nextInt();
        while (T-- != 0) {
            int D = in.nextInt(), P = in.nextInt(), h, d = -1;
            boolean strikes[] = new boolean[D];
            for (int i = 0; i < P; d = -1, i++) {
                h = in.nextInt();
                for (int j = 0; j < D; j++) {
                    d = (d + 1) % (h);
                    strikes[j] |= (d == (h - 1));
                }
            }
            int count = 0;
            for (int i = 0; i < D; i++)
                if (strikes[i] && (i % 7 < 5))
                    count++;

            System.out.println(count);
        }

    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: