zoukankan      html  css  js  c++  java
  • 【Codeforces Round #433 (Div. 2) C】Planning

    【链接】h在这里写链接


    【题意】


    让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样。
    且ti>=i必须成立。

    【题解】


    分解一下成为∑ti*gi - ∑i*gi;
    发现右边是定值。
    左边,只要让大的gi分到尽量小的ti就好。
    写个set,然后lower_bound一下。

    【错的次数】


    0

    【反思】


    在这了写反思

    【代码】

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <set>
    #include <cstdlib>
    #include <cmath>
    #include <bitset>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb emplace_back
    #define fi first
    #define se second
    #define ld long double
    #define ms(x,y) memset(x,y,sizeof x)
    #define ri(x) scanf("%d",&x)
    #define rl(x) scanf("%lld",&x)
    #define rs(x) scanf("%s",x)
    #define rf(x) scnaf("%lf",&x)
    #define oi(x) printf("%d",x)
    #define ol(x) printf("%lld",x)
    #define oc putchar(' ')
    #define os(x) printf(x)
    #define all(x) x.begin(),x.end()
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    #define sz(x) ((int) x.size())
    #define ld long double
    
    
    typedef pair<int, int> pii;
    typedef pair<LL, LL> pll;
    
    
    //mt19937 myrand(time(0));
    //int get_rand(int n){return myrand()%n + 1;}
    const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
    const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
    const double pi = acos(-1.0);
    const int N = 3e5;
    
    
    int n, k;
    pair <LL, int> c[N + 10];
    set <int> myset;
    int ans[N + 10];
    LL temp = 0;
    
    
    int main() {
    	//Open();
    	//Close();
    	ri(n), ri(k);
    
    
    	rep1(i, 1, n) {
    		LL x;
    		rl(x);
    		c[i].fi = x, c[i].se = i;
    	}
    
    
    	rep1(i, 1, n) temp -= (1LL * i*c[i].fi);
    
    
    	rep1(i, 1, n) {
    		myset.insert(k + i);
    	}
    
    
    	sort(c + 1, c + 1 + n);
    
    
    	rep2(i, n, 1) {
    		//cimax
    		int idx = c[i].se;
    		//�ҵ���С��,�Ҵ���idx������
    		auto it = myset.lower_bound(idx);
    		int ju = (*it);
    		temp += 1LL * (*it)*c[i].fi;
    		ans[c[i].se] = (*it);
    		myset.erase(it);
    	}
    	ol(temp), puts("");
    	rep1(i, 1, n)
    		oi(ans[i]), oc;
    	return 0;
    }


  • 相关阅读:
    Centos7安装go.10.1环境
    centos7安装PHP5
    Linux 无文件攻击memfd_create()具体操作步骤
    centos7 '/mnt/hgfs'下共享文件夹不显示问题
    fiddler连接代理手机无法上网问题解决办法
    centos 镜像软件安装包版本低,手动安装过程
    0 upgraded, 0 newly installed, 0 to remove and 112 not upgraded解决方法
    JavaScript高级程序设计(第3版)第七章读书笔记
    JavaScript高级程序设计(第3版)第六章读书笔记
    JavaScript高级程序设计(第3版)第五章读书笔记
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626039.html
Copyright © 2011-2022 走看看