From 7149b8f98dfb3d414733ac3de84306db8928bb21 Mon Sep 17 00:00:00 2001 From: Shaurya Chaubey <52831265+ShauryaChaubey@users.noreply.github.com> Date: Thu, 8 Oct 2020 23:43:52 +0530 Subject: [PATCH] Update 1216 B. Shooting.cpp Solution using multimaps! --- 1216 B. Shooting.cpp | 59 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/1216 B. Shooting.cpp b/1216 B. Shooting.cpp index ea02b69..fbf69ac 100644 --- a/1216 B. Shooting.cpp +++ b/1216 B. Shooting.cpp @@ -1,35 +1,38 @@ -//Bismillahir Rahmanir Rahim -#include -#define ll long long -#define ull unsigned long long +#include +#include +#include + using namespace std; + int main() { - int n,a[1001],b[1001],ans = 0; + int n,sum=0; + multimap map; + + //insertion from user i/p cin>>n; - for(int i=0; i>a[i]; - b[i] = a[i]; + int a,i=0,arr[1000],b[1000]; + for(i=1; i<=n; i++) + { + cin >> a; + map.insert(make_pair(a, i)); } - sort(b,b+n,greater()); - for(int i=0; ifirst; + b[i] = itr->second; + i++; + } + int j = 0; + for(i=n-1; i>=0; i--) + { + sum += arr[i]*j + 1; + j++; + } + cout << sum << endl; + for(i=n-1; i>=0; i--) + { + cout << b[i] << " "; } - cout<