PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000119. Tổng tiền nhỏ nhất không tạo được (Missing Coin Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng tiền nhỏ nhất không tạo được (Missing Coin Sum)
Missing Coin Sum
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You have coins of positive integer values . Each coin can be used at most once. Find the smallest positive integer sum that cannot be formed by any subset.
Input
The first line contains . The next line contains integers .
Output
Print the smallest positive unrepresentable sum.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
5
2 9 1 2 7
Output
6
Explanation
Sorted coins are . Sums through are achievable using the first three coins, but is not achievable because the next coin is .