远端评测题 1000ms 125MiB

[NOIP 2007 普及组] 纪念品分组

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Description

New Year’s Day is coming, and the student council has tasked Lele with distributing souvenirs at the New Year’s party. To keep the value of souvenirs received by participants relatively balanced, he wants to group the purchased souvenirs by price. Each group can contain at most two souvenirs, and the sum of prices in a group cannot exceed a given integer ww. To finish the distribution as quickly as possible, Lele wants to minimize the number of groups.

Your task is to write a program that finds a grouping scheme with the minimal number of groups and outputs that minimal number.

Input Format

A total of n+2n+2 lines:

  • The first line contains an integer ww, the upper bound on the sum of prices in each group.
  • The second line contains an integer nn, the total number of souvenirs.
  • Lines 3 to n+2n+2: each line contains a positive integer PiP_i representing the price of the corresponding souvenir.

Output Format

A single integer: the minimal number of groups.

100 
9 
90 
20 
20 
30 
50 
60 
70 
80 
90

6

Hint

Constraints:

  • 50%50\% of the testdata: 1n151 \le n \le 15.
  • 100%100\% of the testdata: 1n3×1041 \le n \le 3\times 10^4, 80w20080 \le w \le 200, 5Piw5 \le P_i \le w.

Translated by ChatGPT 5

第 25 课:贪心算法

未认领
状态
已结束
题目
21
开始时间
2026-7-7 19:00
截止时间
2026-7-14 19:00
可延期
24 小时