其他分享
首页 > 其他分享> > Codeforces Round #587 (Div. 3) B - Shooting

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 }

 

标签:587,include,10,int,down,cans,knock,Div,Shooting
来源: https://www.cnblogs.com/xwl3109377858/p/11564214.html