[CSP-X2020 山东] 侠盗阿飞

Luogu
IDLGB4090
Time1000ms
Memory512MB
DifficultyP2
贪心2020山东枚举排序CSP-X 小学组
侠盗阿飞获得了一笔意外之财 $w$ 元钱,他想用这笔钱去帮助需要帮助的人。现在知道有 $n$ 个需要帮助的人以及他们每个人需要的钱数 $x_i$ 元($i=0,1,2,3,\dots,n-1$),阿飞应该如何支配这笔钱使得能得到帮助的人数最多? ## Input 第一行:两个数,阿飞的钱数 $w$,需要帮助的人数 $n$。 第二行:$n$ 个数,分别表示第 $i$ 个人需要的钱数 $x_i$。 ## Output 只有一个整数,表示阿飞最多能帮到的人数(最多的人数)。 [samples] ## Note 对于 $30\%$ 的数据,$x_i$ 为升序序列($x_0\lt x_1\lt x_2\lt x_3\lt \dots$)。 对于 $100\%$ 的数据,$0\leq n\leq 500$,$0 \lt x_i\leq 5\times 10^4$,$0\leq w\leq 2\times 10^9$。
Samples
Input #1
10 5
1 2 3 4 5
Output #1
4
Input #2
1000 10
20 20 150 110 180 50 200 140 120 200
Output #2
9
API Response (JSON)
{
  "problem": {
    "name": "[CSP-X2020 山东] 侠盗阿飞",
    "description": {
      "content": "侠盗阿飞获得了一笔意外之财 $w$ 元钱,他想用这笔钱去帮助需要帮助的人。现在知道有 $n$ 个需要帮助的人以及他们每个人需要的钱数 $x_i$ 元($i=0,1,2,3,\\dots,n-1$),阿飞应该如何支配这笔钱使得能得到帮助的人数最多?",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P2"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGB4090"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "侠盗阿飞获得了一笔意外之财 $w$ 元钱,他想用这笔钱去帮助需要帮助的人。现在知道有 $n$ 个需要帮助的人以及他们每个人需要的钱数 $x_i$ 元($i=0,1,2,3,\\dots,n-1$),阿飞应该如何支配这笔钱使得能得到帮助的人数最多?\n\n## Input\n\n第一行:两个数,阿飞的钱数 $w$,需要帮助的人数 $n$。\n\n第二行:$n$ 个数,分别表示第 $i$ 个人需要的钱数 $x_i$...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments