# Marc's Cakewalk

### Problem Statement :

```Marc loves cupcakes, but he also likes to stay fit. Each cupcake has a calorie count, and Marc can walk a distance to expend those calories. If Marc has eaten  cupcakes so far, after eating a cupcake with  calories he must walk at least  miles to maintain his weight.

consumption. In this case, our minimum miles is calculated as .

Given the individual calorie counts for each of the cupcakes, determine the minimum number of miles Marc must walk to maintain his weight. Note that he can eat the cupcakes in any order.

Function Description

Complete the marcsCakewalk function in the editor below.

marcsCakewalk has the following parameter(s):

int calorie[n]: the calorie counts for each cupcake

Returns

long: the minimum miles necessary

Input Format

The first line contains an integer , the number of cupcakes in .
The second line contains  space-separated integers, .```

### Solution :

```                            ```Solution in C :

In  C  :

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

void swap(int *a,int *b)
{
int temp;
temp = *a;
*a = *b;
*b=temp;
}

int partition(int *x,int start,int end)
{
int pivot,pindex,i;
pivot = x[end];
pindex = start;
for(i=start;i<end;i++)
{
if(x[i]>=pivot)
{
swap(&x[i],&x[pindex]);
pindex = pindex + 1;
}
}
swap(&x[pindex],&x[end]);
return pindex;
}
void quicksort(int *x,int start,int end)
{

if(start<end)
{
int i = partition(x,start,end);
quicksort(x,start,i-1);
quicksort(x,i+1,end);

}
}

int main(){
int n;
scanf("%d",&n);
int *calories = malloc(sizeof(int) * n);
for(int calories_i = 0; calories_i < n; calories_i++)
{
scanf("%d",&calories[calories_i]);
}
quicksort(calories,0,n-1);
int i;
long long int sum = 0;
for(i=0;i<n;i++)
{
sum += calories[i]*((long long int)pow(2,i));
}
printf("%lld",sum);
return 0;
}```
```

```                        ```Solution in C++ :

In  C ++  :

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
int n;
while (~scanf("%d", &n)) {
vector<int> c(n);
for (int i = 0; i < n; ++ i)
scanf("%d", &c[i]);
sort(c.begin(), c.end());
ll ans = 0;
rep(i, n)
ans += (ll)c[i] << (n - 1 - i);
printf("%lld\n", ans);
}
return 0;
}```
```

```                        ```Solution in Java :

In  Java :

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] calories = new int[n];
for(int calories_i=0; calories_i < n; calories_i++){
calories[calories_i] = in.nextInt();
}
Arrays.sort(calories);
long ans = 0;
for (int i = 0; i < n; i++) {
ans += ((long)calories[n-i-1])<<i;
}
System.out.println(ans);
}
}```
```

```                        ```Solution in Python :

In  Python3 :

#!/bin/python3

import sys

n = int(input().strip())
calories = list(map(int, input().strip().split(' ')))
calories.sort()

toplam = 0
count = 0
for kalori in calories[::-1]:
toplam += kalori * (2 ** count)
count += 1
print(toplam)```
```

## Super Maximum Cost Queries

Victoria has a tree, T , consisting of N nodes numbered from 1 to N. Each edge from node Ui to Vi in tree T has an integer weight, Wi. Let's define the cost, C, of a path from some node X to some other node Y as the maximum weight ( W ) for any edge in the unique path from node X to Y node . Victoria wants your help processing Q queries on tree T, where each query contains 2 integers, L and

## Contacts

We're going to make our own Contacts application! The application must perform two types of operations: 1 . add name, where name is a string denoting a contact name. This must store name as a new contact in the application. find partial, where partial is a string denoting a partial name to search the application for. It must count the number of contacts starting partial with and print the co

## No Prefix Set

There is a given list of strings where each string contains only lowercase letters from a - j, inclusive. The set of strings is said to be a GOOD SET if no string is a prefix of another string. In this case, print GOOD SET. Otherwise, print BAD SET on the first line followed by the string being checked. Note If two strings are identical, they are prefixes of each other. Function Descriptio

## Cube Summation

You are given a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinate (1,1,1) and the last block is defined by the coordinate (N,N,N). There are two types of queries. UPDATE x y z W updates the value of block (x,y,z) to W. QUERY x1 y1 z1 x2 y2 z2 calculates the sum of the value of blocks whose x coordinate is between x1 and x2 (inclusive), y coor

## Direct Connections

Enter-View ( EV ) is a linear, street-like country. By linear, we mean all the cities of the country are placed on a single straight line - the x -axis. Thus every city's position can be defined by a single coordinate, xi, the distance from the left borderline of the country. You can treat all cities as single points. Unfortunately, the dictator of telecommunication of EV (Mr. S. Treat Jr.) do

## Subsequence Weighting

A subsequence of a sequence is a sequence which is obtained by deleting zero or more elements from the sequence. You are given a sequence A in which every element is a pair of integers i.e A = [(a1, w1), (a2, w2),..., (aN, wN)]. For a subseqence B = [(b1, v1), (b2, v2), ...., (bM, vM)] of the given sequence : We call it increasing if for every i (1 <= i < M ) , bi < bi+1. Weight(B) =