URAL1964:Chinese Dialects

Open Ural FU Personal Contest 2013


Vova moved from Guangzhou to Shenzhen. He immediately found out that the local people don't understand his Cantonese phrases as well. Vova tried chatting with them in Mandarin, but to no success.
Then Vova decided to learn more about Chinese dialects. It turned out that people in China speak  kdifferent dialects, at that at least  a 1 people speak the first dialect, at least  a 2 people speak the second dialect, …, at least  a k people speak the  k-th dialect. How many people speak all  k dialects if the population of China is  n people?

Input

The first line contains integers  n and  k (2 ≤  k ≤ 20; 1 ≤  n ≤ 10 9). The second line contains space-separated integers  a 1, …,  a k (1 ≤  a k ≤  n).

Output

Print the minimum number of people in China that speak all  k dialects of the Chinese language.

Samples

input output
1000000000 2
800000000 800000000
600000000
1000000000 2
500000000 500000000
0

题意:有n个人,有m种语言,然后m个输入代表每种语言有几个人会讲,要求会讲所有语言的人有几个


思路:对于两种语言的话,我们不难发现必然是a1+a2-n,那么我们以此类推,先求出会讲两种语言的人数,在把会讲两种语言的人看做一种,循环计算下去求得会讲所有语言的人有几个


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define Len 200005
#define mod 19999997
const int INF = 0x3f3f3f3f;

LL n,m,N,M;

int main()
{
    w(~scanf("%I64d%I64d",&n,&m))
    {
        LL t = n,x;
        w(m--)
        {
            scanf("%I64d",&x);
            t = max(0LL,t+x-n);
        }
        printf("%I64d\n",t);
    }

    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值