首页 > 其他 > 详细

Poor Folk Gym - 102299K(思维题)

时间:2019-08-21 20:08:34      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:hat   ack   char   put   组成   ice   val   was   ucc   

 Russian writers are known worldwide. One of the main Russian authors is Fyódor Dostoyévskiy. The influence of his works outgrew literature itself and reached other areas such as Philosophy, Psychology, and Theology. His first successful book was "Poor Folk", published in 1846.

技术分享图片

 This broad and impacting influence is due in part to the deep psychological description of his characters. However, some have criticized him for writing stories which are too long and even weary. Even though he is considered a great writer, Dostoyévskiy‘s life was not easy. In many occasions he had to write under pressure to make a living and perhaps his prolificacy came from such moments of needs.

 Dostoyévskiy‘s only way to obtain money is by selling chapters of his books. Moreover, he knows the editor would buy each and every chapter he wrote — after all, he is a great writer. However, he wants more than just selling all the chapters he is writing. He noted that his financial woes are cause by his lack of financial discipline. That is why Dostoyévskiy decided that whenever he needs to pay his debts, he will choose some chapters to sell so that the money earned is exactly the amount owed. In this way, he will never have any savings and he will have no need to be disciplined about spending.

 Of course he understands there could be some debts he will not be able to pay if he insists on this rule. Thus, knowing the value in rubles for each chapter he already wrote, one of the questions he raised was: what is the smallest debt that he would not be able to pay with previously written chapters? Your task is to answer this question.

Input

You should read an integer (n) in the first line, the number of chapters already written by Dostoyévskiy. The second line has (n) integers, p1,p2,,pnp1,p2,…,pn, the price in rubles for each of the (n) chapters.

Constraints

  • 1n51051≤n≤5⋅105.
  • 1pi10121≤pi≤1012, for all ii.

Output

A single positive integer, the value of the smallest amount of debt as described above.

Examples

Input
3
2 1 10000000000
Output
4
Input
1
2
Output
1
 
题意:
给出的n个数,求不能组成的最小的数
 
思维题
 
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 long long n, sum, a[500005], i;
 6 
 7 int main()
 8 {
 9     scanf("%lld", &n);
10     for(i=0;i<n;i++)
11     {
12         scanf("%lld", &a[i]);
13     }
14     sort(a, a+n);
15     sum = 0;
16     for(i=0;i<n;i++)
17     {
18         if(a[i]>sum+1) break;
19         sum += a[i];
20     }
21     printf("%lld\n", sum+1);
22     return 0;
23 }

 

 

Poor Folk Gym - 102299K(思维题)

标签:hat   ack   char   put   组成   ice   val   was   ucc   

原文:https://www.cnblogs.com/0xiaoyu/p/11390662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号