PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000146. Nhóm bò có tổng chia hết cho 7 (Subsequences Summing to Sevens)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nhóm bò có tổng chia hết cho 7 (Subsequences Summing to Sevens)
Subsequences Summing to Sevens
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Farmer John has cows in a row, with distinct integer IDs . He wants to photograph a consecutive group whose IDs sum to a multiple of 7. Find the largest possible number of cows in such a nonempty group, or 0 if no group qualifies.
Input
- Line 1: integer , the number of cows.
- The next lines each contain one ID; the -th of these lines contains .
Output
Print the largest qualifying group size, or 0 if none exists.
Subtasks
- Subtask 1 (20 points): ; for every ; All IDs are pairwise distinct.
- Subtask 2 (30 points): ; for every ; All IDs are pairwise distinct; Every ID is divisible by 7.
- Subtask 3 (50 points): ; for every ; All IDs are pairwise distinct.
Example 1
Input
7
3
5
1
6
2
14
10
Output
5
Explanation
Positions 2 through 6 sum to . The two groups of length 6 sum to 31 and 38; the entire row sums to 41. No longer group qualifies.