【链接】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;
}

【Codeforces Round #433 (Div. 2) C】Planning的更多相关文章

  1. 【Codeforces Round #433 (Div. 1) B】Jury Meeting

    [链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...

  2. 【Codeforces Round #433 (Div. 2) B】Maxim Buys an Apartment

    [链接]h在这里写链接 [题意] 你有n个位置,然后其中有k个地方是已经被人占据了的. 一个"好的位置"的定义是指,这个位置相邻的地方其中至少有一个被人占据了. k个被人占据的位置 ...

  3. 【Codeforces Round #433 (Div. 2) A】Fraction

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举分子从高到低就好. 这样得到的一定是最大的. (可以约分没错,但是约分过后和就不是n了,所以不会有错的) [错的次数] 0 [反思] 在这 ...

  4. 【Codeforces Round #433 (Div. 1) C】Boredom(二维线段树)

    [链接]我是链接 [题意] 接上一篇文章 [题解] 接(点我进入)上一篇文章. 这里讲一种用类似二维线段树的方法求矩形区域内点的个数的方法. 我们可以把n个正方形用n棵线段树来维护. 第i棵线段树维护 ...

  5. 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)

    [链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...

  6. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  7. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  8. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  9. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

随机推荐

  1. Linux局域网登陆响应时间过长

    在局域网中,使用ssh登陆到其他机器上时,有时会出现等待10s以上才能正常登陆的问题. 原因: Linux默认使用dns解析登陆IP,但是在局域网,并没有dns服务器,而且机器上也没有添加 IP与域名 ...

  2. log4j小结

    核心包: org.apache.log4j 三大组件 Loggers 日志操作 Appenders 日志的展现形式 Layouts 日志的展现格式 日志等级 TRACE DEBUG INFO WARN ...

  3. jquery12 queue() : 队列方法

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  4. 5.cocos2d锚点

    创建一个层T1LayerAnchorPoint AppDelegate.cpp bool AppDelegate::applicationDidFinishLaunching() { // initi ...

  5. tortoisegit--无法commit

    tortoisegit--无法提交,好几次使用tortoisegit,commit的时候出现卡死的情况,导致无法提交代码. 分析错误以为是: 电脑的性功能有关,但重启好几次电脑一人无济于事,打开任务管 ...

  6. 「HAOI2018」字串覆盖

    「HAOI2018」字串覆盖 题意: ​ 给你两个字符串,长度都为\(N\),以及一个参数\(K\),有\(M\)个询问,每次给你一个\(B\)串的一个子串,问用这个字串去覆盖\(A\)串一段区间的最 ...

  7. command---调用指定的指令并执行

    command命令调用指定的指令并执行,命令执行时不查询shell函数.command命令只能够执行shell内部的命令. 语法 command(参数) 参数 指令:需要调用的指令及参数. 实例 使用 ...

  8. C++里面virtual函数及虚表大小

    实验了下面的函数: #include <vector> #include <iostream> using namespace std; class A { public: v ...

  9. android图片特效处理之锐化效果

    这篇将讲到图片特效处理的锐化效果.跟前面一样是对像素点进行处理,算法是通用的. 算法原理: 一.简单算法:分别获取当前像素点和八个周围像素点的RGB值,先求出当前像素点的RGB值与八个像素点RGB值的 ...

  10. Five ways to maximize Java NIO and NIO.2--转

    原文地址:http://www.javaworld.com/article/2078654/java-se/java-se-five-ways-to-maximize-java-nio-and-nio ...