zoukankan      html  css  js  c++  java
  • cf Coffee and Coursework (Hard Version)

    D2. Coffee and Coursework (Hard Version)
    time limit per test
    2.5 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The only difference between easy and hard versions is the constraints.

    Polycarp has to write a coursework. The coursework consists of m

    pages.

    Polycarp also has n
    cups of coffee. The coffee in the i-th cup Polycarp has ai

    caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).

    Surely, courseworks are not being written in a single day (in a perfect world of Berland, at least).

    Let's consider some day of Polycarp's work. Consider Polycarp drinks k
    cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are ai1,ai2,…,aik. Then the first cup he drinks gives him energy to write ai1 pages of coursework, the second cup gives him energy to write max(0,ai2−1) pages, the third cup gives him energy to write max(0,ai3−2) pages, ..., the k-th cup gives him energy to write max(0,aik−k+1)

    pages.

    If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.

    Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
    Input

    The first line of the input contains two integers n
    and m (1≤n≤2⋅105, 1≤m≤109

    ) — the number of cups of coffee and the number of pages in the coursework.

    The second line of the input contains n
    integers a1,a2,…,an (1≤ai≤109), where ai is the caffeine dosage of coffee in the i

    -th cup.
    Output

    If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
    二分傻题

    #include <bits/stdc++.h>
    using namespace std;
    const int max_n = 200222, inf = 1000111222;
    int n, m, a[max_n];
    bool check(int cnt) 
    {
        long long sum = 0;
        int last = 1;
        for (int i = 0; i < n; ++i) 
        {
            if (i % cnt == 0) --last;
            if (a[i] + last > 0) sum += (a[i] + last);
        }
        return sum >= m;
    }
    int main()
    {
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; ++i) 
            scanf("%d", &a[i]);
        sort(a, a + n);
        reverse(a, a + n);
        int l = 0, r = n + 1;
        while (r - l > 1)
        {
            int mid = (l + r) / 2;
            if (check(mid)) r = mid;
            else l = mid;
        }
        if (r > n) puts("-1");
        else printf("%d
    ", r);
        return 0;
    }
    
    我现在最大的问题就是人蠢而且还懒的一批。
  • 相关阅读:
    周赛D. Digging for Gold(扫描线)
    CF1209F Koala and Notebook(最短路+拆点)
    P6793 [SNOI2020]字符串(后缀树上DP)
    [HEOI2016/TJOI2016]字符串(后缀自动机,可持久化线段树,线段树合并,二分答案)
    CF1166F Vicky's Delivery Service(并查集,启发式合并)
    P4248 [AHOI2013]差异(后缀树)
    CF1175F The Number of Subpermutations(单调栈,ST表)
    CF666E Forensic Examination(后缀自动机,可持久化线段树合并)
    GYM103069G. Prof. Pang's sequence
    [转]C#、VB.NET使用HttpWebRequest访问https地址(SSL)的实现
  • 原文地址:https://www.cnblogs.com/pot-a-to/p/10937021.html
Copyright © 2011-2022 走看看