• <cf>A. Exams


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

    One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.

    The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all.

    The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.

    Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.

    Input

    The single input line contains space-separated integers n and k (1 ≤ n ≤ 501 ≤ k ≤ 250) — the number of exams and the required sum of marks.

    It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.

    Output

    Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.

    Sample test(s)
    input
    4 8
    
    output
    4
    
    input
    4 10
    
    output
    2
    
    input
    1 3
    
    output
    0
    
    Note

    In the first sample the author has to get a 2 for all his exams.

    In the second sample he should get a 3 for two exams and a 2 for two more.

    In the third sample he should get a 3 for one exam.

    思路:当k==2*n时,要重考n次,当k>=3*n时不需要重考,关键是2*n<k<3*n时,k比2*n大多少就要重考多少次。就是

    补考 次数=n-(k-2*n) (2*n<=k<3*n); 补考次数=0(k>=3*n)

    #include <iostream>
    using namespace std;
    int main()
    {
        int n,k,sum;
        while(cin>>n>>k)
        {
            if(3*n<=k) sum=0;
            //2*n<=k<3*n
            else sum=n-(k-2*n);
            cout<<sum<<endl;
        }
        return 0;
    }



  • 相关阅读:
    python函数应用
    python文件操作
    设计模式大杂烩(24种设计模式的总结以及学习设计模式的几点建议)
    (二十四)解释器模式详解
    (二十三)原型模式详解(clone方法源码的简单剖析)
    (二十二)访问者模式详解(伪动态双分派)
    (二十一)状态模式详解(DOTA版)
    (二十)职责链模式详解(都市异能版)
    (十九)组合模式详解
    (十八)享元模式详解(都市异能版)
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910589.html
Copyright © 2020-2023  润新知