Hihocoder 1269 Optimization Delay (two-point, priority queue)

Source: Internet
Author: User

Test instructions

is not very good explanation, anyway the Chinese topic will not write is not very good explanation, anyway the Chinese question will not write

Analysis:

The larger the cache, the more we can get the largest number, and then make its contribution smaller to find that the larger the cache, the more we will be able to take out the largest number and make its contribution smaller.
So there's a monotonically decreasing nature, and as the cache gets bigger, there's monotonically diminishing, as the cache gets bigger.
Then the direct binary cache size, priority queue simulation can then direct two-point cache size, priority queue simulation can be

Code:

Created by Taosama on 2016-03-06//Copyright (c) Taosama.
All rights reserved. #pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> # Include <iostream> #include <map> #include <queue> #include <string> #include <set> #
Include <vector> using namespace std; #define PR (x) cout << #x << "=" << x << "" #define PRLN (x) cout << #x << "=" &lt

;< x << Endl const int N = 1e5 +, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

typedef long Long LL;
int n, a[n];

LL Q;
    BOOL Check (int x) {priority_queue<int> q;
    LL ret = 0;
    int j = 1;
            for (int i = 1; I <= n; ++i) {if (q.size () = = x) {int cur = q.top (); Q.pop ();
        RET + = cur * j + +;
    } q.push (A[i]); } while (Q.Size ()) {int cur = q.top (); Q.pop ();
    RET + = cur * j + +;
} return ret <= Q; } int main () {#ifdef LOCAL freopen ("C:\\users\\taosama\\desktop\\in.txt", "R", stdin);//Freopen ("C:\\users\\taosa
Ma\\desktop\\out.txt "," w ", stdout);

    #endif ios_base::sync_with_stdio (0);
    scanf ("%d%lld%", &n, &q);
    for (int i = 1; I <= n; ++i) scanf ("%d", A + i);
    int L = 1, r = 100000;
        while (L <= r) {int m = l + R >> 1;
        if (check (m)) R = m-1;
    else L = m + 1;
    } if (L > 100000) L =-1;
    printf ("%d\n", L);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.