• CodeForces 1185C1 Exam in BerSU (easy version) (贪心,排序)


    C1. Exam in BerSU (easy version)

    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    The only difference between easy and hard versions is constraints.

    A session has begun at Beland State University. Many students are taking exams.

    Polygraph Poligrafovich is going to examine a group of n<?XML:NAMESPACE PREFIX = [default] http://www.w3.org/1998/Math/MathML NS = "http://www.w3.org/1998/Math/MathML" />n students. Students will take the exam one-by-one in order from 11-th to nn-th. Rules of the exam are following:

    • The ii-th student randomly chooses a ticket.
    • if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
    • if the student finds the ticket easy, he spends exactly titi minutes to pass the exam. After it, he immediately gets a mark and goes home.

    Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

    The duration of the whole exam for all students is MM minutes (maxti≤Mmaxti≤M), so students at the end of the list have a greater possibility to run out of time to pass the exam.

    For each student ii, you should count the minimum possible number of students who need to fail the exam so the ii-th student has enough time to pass the exam.

    For each student ii, find the answer independently. That is, if when finding the answer for the student i1i1 some student jj should leave, then while finding the answer for i2i2 (i2>i1i2>i1) the student jj student does not have to go home.

    Input

    The first line of the input contains two integers nn and MM (1≤n≤1001≤n≤100, 1≤M≤1001≤M≤100) — the number of students and the total duration of the exam in minutes, respectively.

    The second line of the input contains nn integers titi (1≤ti≤1001≤ti≤100) — time in minutes that ii-th student spends to answer to a ticket.

    It's guaranteed that all values of titi are not greater than MM.

    Output

    Print nn numbers: the ii-th number must be equal to the minimum number of students who have to leave the exam in order to ii-th student has enough time to pass the exam.

    Examples

    input

    Copy

    7 15
    1 2 3 4 5 6 7
    

    output

    Copy

    0 0 0 0 0 2 3 

    input

    Copy

    5 100
    80 40 40 40 60
    

    output

    Copy

    0 1 1 2 3 
    由于开始忘了在每次循环后把sumn的值置为0,就一直WA
    代码如下:
    #include <iostream>
    #include <cstdio>
    using namespace std;
    int main(){
        int n, m;
        int a[100];
        int i;
        int sum = 0;
        int sumn = 0;
        scanf("%d %d", &n, &m);
            for (i = 1; i <= n; i++){
                scanf("%d", &a[i]);
            }
            for (i = 1; i <= n; i++){
                sumn = 0;  //开始漏了这一步。。。
                sum += a[i];
                if (sum <= m){
                    printf("0");
                    if (i != n)
                        printf(" ");
                    if (i == n)
                        printf("
    ");
                }
                else {
                
                    for (int j = 1; j <= i - 2; j++){
                        for (int k = 1; k <= i - j - 1; k++){
                            if (a[k] > a[k + 1]){
                                int temp = a[k];
                                a[k] = a[k + 1];
                                a[k + 1] = temp;
                            }
                        }
                    }
                    for (int s = 1; s <= i - 1; s++){
                        sumn += a[s];
                        if ((sumn + a[i] > m) && (sumn - a[s] + a[i] <= m)){
                            printf("%d", i - s);
                            if (i != n)
                                printf(" ");
                            if (i == n)
                                printf("
    ");
                        }
                    }
                }
            }
        return 0;
    }
    天晴了,起飞吧
  • 相关阅读:
    Go语言中new()和 make()的区别详解
    对于Linux内核tty设备的一点理解
    中国移动MySQL数据库优化最佳实践
    深入分析Linux自旋锁
    JAVA大数据项目+整理的Mysql数据库32条军规
    MySQL DBA面试全揭秘
    LINUX 内核基础
    子查询
    linuxprobe----LINUX 基础课程目录学习
    从事分布式系统,计算,hadoop
  • 原文地址:https://www.cnblogs.com/jianqiao123/p/11221135.html
Copyright © 2020-2023  润新知