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;
    }


  • 相关阅读:
    国家行政区划地区编码表
    Java循环中标签的作用(转)
    通过ribbon 根据服务名获取所有服务实例的IP和端口列表
    rabbitmq重装依赖的erlang 要注意
    Rabbitmq关于集群节点功能的读书笔记
    CentOS7统计某个进程当前的线程数
    理解同步、异步、阻塞、非阻塞(传送门)
    代理模式和装饰模式区别
    【转载】Asp.Net生成图片验证码工具类
    【转载】使用宝塔Linux面板屏蔽某些IP访问你的服务器
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626039.html
Copyright © 2011-2022 走看看