CF725E.Too Much Money

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alfred wants to buy a toy moose that costs cc dollars. The store doesn’t give change, so he must give the store exactly cc dollars, no more and no less. He has nn coins. To make cc dollars from his coins, he follows the following algorithm: let SS be the set of coins being used. SS is initially empty. Alfred repeatedly adds to SS the highest-valued coin he has such that the total value of the coins in SS after adding the coin doesn’t exceed cc . If there is no such coin, and the value of the coins in SS is still less than cc , he gives up and goes home. Note that Alfred never removes a coin from SS after adding it.

As a programmer, you might be aware that Alfred’s algorithm can fail even when there is a set of coins with value exactly cc . For example, if Alfred has one coin worth $3, one coin worth$4, and two coins worth $5, and the moose costs$12, then Alfred will add both of the 5coinsto5 coins to S andthengiveup,sinceaddinganyothercoinwouldcausethevalueofthecoinsinand then give up, since adding any other coin would cause the value of the coins in S $to exceed$12. Of course, Alfred could instead combine one $3 coin, one$4 coin, and one $5 coin to reach the total.

Bob tried to convince Alfred that his algorithm was flawed, but Alfred didn’t believe him. Now Bob wants to give Alfred some coins (in addition to those that Alfred already has) such that Alfred’s algorithm fails. Bob can give Alfred any number of coins of any denomination (subject to the constraint that each coin must be worth a positive integer number of dollars). There can be multiple coins of a single denomination. He would like to minimize the total value of the coins he gives Alfred. Please find this minimum value. If there is no solution, print "Greed is good". You can assume that the answer, if it exists, is positive. In other words, Alfred's algorithm will work if Bob doesn't give him any coins.

输入格式

The first line contains cc ( 1<=c<=2000001<=c<=200000 ) — the price Alfred wants to pay. The second line contains nn ( 1<=n<=2000001<=n<=200000 ) — the number of coins Alfred initially has. Then nn lines follow, each containing a single integer xx ( 1<=x<=c1<=x<=c ) representing the value of one of Alfred's coins.

输出格式

If there is a solution, print the minimum possible total value of the coins in a solution. Otherwise, print "Greed is good" (without quotes).

输入输出样例

  • 输入#1

    12
    3
    5
    3
    4
    

    输出#1

    5
    
  • 输入#2

    50
    8
    1
    2
    4
    8
    16
    37
    37
    37
    

    输出#2

    Greed is good
    

说明/提示

In the first sample, Bob should give Alfred a single coin worth $5. This creates the situation described in the problem statement.

In the second sample, there is no set of coins that will cause Alfred's algorithm to fail.

首页