zoukankan      html  css  js  c++  java
  • Poor Folk Gym

     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
    ", sum+1);
    22     return 0;
    23 }
     
  • 相关阅读:
    Python 学习笔记(七)Python字符串(三)
    Python 学习笔记(七)Python字符串(二)
    Python 学习笔记(六)Python第一个程序
    Python 学习笔记(五)常用函数
    Python 学习笔记(四)数字(二)
    行为型模式之责任链模式
    python_frm组件
    django之models学习总结
    HTTP协议
    事件委托
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11390662.html
Copyright © 2011-2022 走看看