zoukankan      html  css  js  c++  java
  • (CF1394 A)Boboniu Chats with Du

    开始本来以为可以直接贪心的。。。最后还是得dp统计答案

    ①把大于m和小于等于m的分成2组降序求前缀和,小于等于m的size为cnt,大于的为tot

    ②将i从0枚举到cnt,指选择i个小于等于m的数(从大到小贪心),剩下n-i个数,再从其中选择(n-i+d)/(d+1)个禁言单元(每一次禁言消耗d+1天,但最后一个单元的禁言时间可以超过n,因此需要上取整)

    \(ans=max(ans,a[i] + (bigsiz > tot ? b[tot] : b[bigsiz]))\);

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    const int maxn = 1e5 + 10;
    const int inf = 1e8;
    ll mod = 1e9 + 7;
    
    int cnt, tot;
    
    void pre(vector<ll> &a,int n)
    {
        sort(a.begin() + 1, a.end(), greater<>());
        for (int i = 1; i <= n; i++)
            a[i] += a[i - 1];
    }
    
    int main()
    {
        //freopen("C:\\1.in", "r", stdin);
        fastio;
        ll n, m, d;
        cin >> n >> d >> m;
        vector<ll>a(n + 1), b(n + 1);
        for (int i = 1; i <= n; i++)
        {
            ll x;
            cin >> x;
            if (x <= m)a[++cnt] = x;
            else b[++tot] = x;
        }
        pre(a, cnt);
        pre(b, tot);
        ll ans = 0;
        for (int i = 0; i <= cnt; i++)
        {
            int bigsiz = (n - i + d) / (d + 1);//剩下的除d+1上取整
            ans = max(ans, a[i] + (bigsiz > tot ? b[tot] : b[bigsiz]));
        }
        cout << ans;
    
        return 0;
    
    }
    
  • 相关阅读:
    test
    Android初学-AsyncTask下载网络图片
    SFTP Using Chilkat Active component
    test wilddog
    c# multi-ply download ui
    VB6 Common Dialog
    Advanced Find and Replace(文件内容搜索替换工具)v7.8.1简体中文破解版
    【Unity Shaders】Shader中的光照
    GDAL不支持创建PCIDSK的面状矢量格式
    CentOs查看文件的几种方式
  • 原文地址:https://www.cnblogs.com/ruanbaiQAQ/p/13500884.html
Copyright © 2011-2022 走看看