Codeforces Round #587 (Div. 3) B - Shooting

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564214.html

Codeforces Round #587 (Div. 3)

B - Shooting

Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.

Vasya knows that the durability of the i-th can is ai. It means that if Vasya has already knocked x cans down and is now about to start shooting the i-th one, he will need (ai⋅x+1) shots to knock it down. You can assume that if Vasya starts shooting the i-th can, he will be shooting it until he knocks it down.

Your task is to choose such an order of shooting so that the number of shots required to knock each of the n given cans down exactly once is minimum possible.

Input

The first line of the input contains one integer n (2≤n≤1000) — the number of cans.

The second line of the input contains the sequence a1,a2,…,an (1≤ai≤1000), where ai is the durability of the i-th can.

Output

In the first line print the minimum number of shots required to knock each of the n given cans down exactly once.

In the second line print the sequence consisting of n distinct integers from 1 to n — the order of indices of cans that minimizes the number of shots required. If there are several answers, you can print any of them.

Examples

input

3

20 10 20

output

43

1 3 2

input

4

10 10 10 10

output

64

2 1 4 3

input

6

5 4 5 4 4 5

output

69

6 1 3 5 2 4

input

2

1 4

output

3

2 1

Note

In the first example Vasya can start shooting from the first can. He knocks it down with the first shot because he haven‘t knocked any other cans down before. After that he has to shoot the third can. To knock it down he shoots 20⋅1+1=21 times. After that only second can remains. To knock it down Vasya shoots 10⋅2+1=21 times. So the total number of shots is 1+21+21=43.

In the second example the order of shooting does not matter because all cans have the same durability.

题意:给你n个数,第i次取数需要 ai*(i-1)+1 次,问你取完n个数最少需要多少次,

并输出取数次序的下标。

思路:既然要求最少的次数,那么我们应该从最大的数开始取,因为要输出次序,

那么要记录一下每个数的初始下标,再结构体排序就好了。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<list>
11 #include<stack>
12 using namespace std;
13 #define ll long long
14 const int mod=1e9+7;
15 const int inf=1e9+7;
16
17 const int maxn=1e3+10;
18
19 typedef struct
20 {
21     int num;
22     int id;
23 }St;
24
25 St sum [maxn];
26
27 inline bool cmp(const St &a,const St &b)
28 {
29     return a.num > b.num;
30 }
31
32 int main()
33 {
34     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
35
36     int n;
37     cin>>n;
38
39     for(int i=1;i<=n;i++)
40     {
41         cin>>sum[i].num;
42         sum[i].id=i;
43     }
44
45     sort(sum+1,sum+n+1,cmp);
46
47     ll int ans=0;
48
49     for(int i=1;i<=n;i++)
50         ans+=(i-1)*sum[i].num+1;
51
52     cout<<ans<<endl;
53
54     for(int i=1;i<=n;i++)
55         cout<<sum[i].id<<" ";
56
57     return 0;
58 }

原文地址:https://www.cnblogs.com/xwl3109377858/p/11564214.html

时间: 2024-11-08 18:36:00

Codeforces Round #587 (Div. 3) B - Shooting的相关文章

Codeforces Round #587 (Div. 3) C - White Sheet

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564279.html Codeforces Round #587 (Div. 3) C - White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you w

Codeforces Round #587 (Div. 3) D - Swords

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564317.html Codeforces Round #587 (Div. 3) D -Swords There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people

White Sheet (矩形面积模板) (Codeforces Round #587 (Div. 3) )

There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0)(0,0),

Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordina

Codeforces Round #587 (Div. 3) F Wi-Fi(线段树+dp)

题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int N = 2e5+7; typedef long long ll; const ll mod

Codeforces Round #587 (Div. 3)

C. White Sheet 一道基础的几何题  给定三个矩形的左下角坐标和右上角坐标,第一块是白色矩形,第二第三都是黑色矩形,问白色矩形是否被黑色矩形完全覆盖.思路就是根据点判断分类讨论. 1.如果白色矩形的四个点没有全部被覆盖了   那么直接输出“NO” 2.如果白色矩形的四个点都被覆盖了,那么就再判断下黑色的矩形有没有交集 1 #include <math.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #inclu

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我