Codeforces 149A Business trip【水题】

Petya的父母出差一年,留给他一项任务:每天给最喜欢的花浇水。如果Petya在第i个月完成任务,花将生长ai厘米。他需要确保花至少生长k厘米,找出最小的浇水月份数。输入k和12个月的增长值,输出能达成目标的最小月份数或-1表示无法达成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Business trip
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...

Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≤ i ≤ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters.

Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by kcentimeters.

Input

The first line contains exactly one integer k (0 ≤ k ≤ 100). The next line contains twelve space-separated integers: the i-th (1 ≤ i ≤ 12) number in the line represents ai (0 ≤ ai ≤ 100).

Output

Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by kcentimeters. If the flower can't grow by k centimeters in a year, print -1.

Sample test(s)
input
5
1 1 1 1 2 2 3 2 2 1 1 1
output
2
input
0
0 0 0 0 0 0 0 1 1 2 3 0
output
0
input
11
1 1 4 1 1 5 1 1 4 1 1 1
output
3
Note

Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.

In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all.


题意:给定12个数,让你从中选最少的数使得这些数之和大于等于k。若可以输出选数的个数,反之输出-1。

水题。。。


AC代码:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (2100+10)
#define MAXM (200000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 10007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
using namespace std;
int a[20];
int main()
{
    int n; Ri(n);
    for(int i = 0; i < 12; i++)
        Ri(a[i]);
    sort(a, a+12);
    int cnt = 0; bool flag = false;
    for(int i = 11; i >= 0; i--)
    {
        if(n <= 0)
        {
            flag = true;
            break;
        }
        cnt++; n -= a[i];
    }
    if(n <= 0)
        flag = true;
    printf(flag ? "%d\n" : "-1\n", cnt);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值