zoukankan      html  css  js  c++  java
  • B. Valera and Contest

    B. Valera and Contest
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.

    After the contest was over, Valera was interested in results. He found out that:

    • each student in the team scored at least l points and at most r points;
    • in total, all members of the team scored exactly sall points;
    • the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 ≥ a2 ≥ ... ≥ an), then sk = a1 + a2 + ... + ak.

    However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.

    Input

    The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 ≤ n, k, l, r ≤ 1000; l ≤ r; k ≤ n; 1 ≤ sk ≤ sall ≤ 106).

    It's guaranteed that the input is such that the answer exists.

    Output

    Print exactly n integers a1, a2, ..., an — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.

    Sample test(s)
    Input
    5 3 1 3 13 9
    Output
    2 3 2 3 3 
    Input
    5 3 1 3 15 9
    Output
    3 3 3 3 3 
    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define maxn 1010
    #define LL long long
    #define mod 1000000007
    using namespace std ;
    
    int ans[maxn] , tt , mm , sk , ll ;
    bool getans( int u , int L , int R )
    {
        if( mm == sk ) return true ;
    
            ans[u]++ ;
            mm++ ;
            if(tt)tt-- ;
            else
            {
                ans[ll]-- ;
                if(ans[ll] <= L) ll-- ;
            }
            if(mm == sk ) return true ;
            return false ;
    }
    int main()
    {
       int i , n ,m , j , k;
       int L , R , sum ;
      // freopen("in.txt","r",stdin) ;
       while( scanf("%d%d%d%d%d%d" , &n,&k,&L,&R,&sum,&sk ) != EOF )//n, k, l, r, sall, sk
       {
            j = sum/n ;
            tt = sum%n ;
            mm = 0 ;
            ll = n ;
            for( i = 1 ; i <= n ;i++ ){
                ans[i] = j ;
                if(i <= k) mm += j ;
            }
            i = 1 ;
              while(1){
                if(getans(i,L,R))break ;  // 每次都给一个增加1 
                  i++ ;
                if( i > k ) i = 1 ;
              }
            
           if(tt)
            {
                for( i = k+1 ; i <= n ;i++ )
                {
                    while( ans[i] < ans[k])
                    {
                        ans[i]++ ;
                        tt-- ;
                        if(tt==0) break ;
                    }
                    if(tt==0)break ;
                }
            }
            
         for( i = 1 ; i < n ;i++ ){
              printf("%d " ,ans[i]) ;
            }
            cout << ans[i] << endl ;
       }
       return 0 ;
    }
    
  • 相关阅读:
    [一个64位操作系统的设计与实现] 3.1 Func_GetFATEntry疑惑
    【参考】 实现X86_64架构下的BootLoader(二)文件系统
    LBA和CHS转换(转)
    Grafana 重置admin密码
    linux-source: not found ubuntu执行脚本报错
    Hbase学习
    高并发理解
    Linux下安装Artemis
    SpringInAction 第八章 发送异步消息
    SpringInAction 六七章总结
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3450715.html
Copyright © 2011-2022 走看看