zoukankan      html  css  js  c++  java
  • Codeforces Round #193 (Div. 2) B



    B. Maximum Absurdity
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.

    This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers ab (1≤abn-k+1,b-ak) and sign all laws with numbers lying in the segments [aa+k-1] and [bb+k-1] (borders are included).

    As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.

    Input

    The first line contains two integers n and k (2≤n≤2·1050<2kn) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1,x2,...,xn — the absurdity of each law (1≤xi≤109).

    Output

    Print two integers ab — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [aa+k-1] and [bb+k-1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.

    Sample test(s)
    input
    5 2
    3 6 1 1 6
    output
    1 4
    input
    6 2
    1 1 1 1 1 1
    output
    1 3
    Note

    In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3+6+1+6=16.

    In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1+1+1+1=4.


    类似优先队列的优化+剪枝+long long int

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <algorithm>

    using namespace std;

    long long int num[201000];
    long long int sum[201000];

    struct Node
    {
        long long int val;
        int id;
    }nb[201000];

    bool cmp(Node a,Node b)
    {
        if(a.val!=b.val)
        {
            return a.val>b.val;
        }
        else
        {
            return a.id<b.id;
        }

    }

    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        long long int sst=0;
        for(int i=1;i<=n;i++)
        {
            cin>>num;
            sst+=num;
            if(i>=k)
            {
                sst-=num[i-k];
                sum[i-k+1]=sst;
                nb[i-k+1].val=sum[i-k+1];
                nb[i-k+1].id=i-k+1;
            }
        }

        sort(nb+1+k,nb+n-k+2,cmp);
    /*
        for(int j=1+k;j<=n-k+2;j++)
            cout<<nb[j].id<<": "<<nb[j].val<<endl;
        cout<<"------ ";
    */
        int posa=1,posb=1+k;long long int ppt=-0x3f3f3f3f;
        long long int temp=-0x3f3f3f3f,mmx=-0x3f3f3f3f;
        for(int i=1;i<=n-2*k+1;i++)
        {
            if(sum<=ppt) continue;
            for(int j=1+k;j<=n-k+1;j++)
            {
                if(nb[j].id>=i+k)
                {
                    ppt=sum;
                    temp=sum+nb[j].val;
                    if(temp>mmx)
                    {
                  //      cout<<mmx<<" : "<<temp<<endl;
                 //       cout<<posa<<"--->"<<i<<endl;
                //       cout<<posb<<"--->"<<nb[j].id<<endl;
                        posa=i;
                        posb=nb[j].id;
                        mmx=temp;
                    }
                    break;
                }
            }
        }
        printf("%d %d ",posa,posb);
        return 0;
    }

  • 相关阅读:
    敏捷冲刺二
    敏捷冲刺一
    软工网络15-Alpha阶段敏捷冲刺
    Scrum 冲刺博客
    软工网络15团队作业3——需求分析与设计
    软工网络15团队作业2——团队计划
    软件网络15团队作业1
    【Alpha阶段】第一次Scrum Meeting
    Scrum 冲刺博客集合
    第 1 篇 Scrum 冲刺博客
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350945.html
Copyright © 2011-2022 走看看