0% found this document useful (0 votes)
28 views3 pages

CSS 215-13L SH Without Answers

Uploaded by

barlykov99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

CSS 215-13L SH Without Answers

Uploaded by

barlykov99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSS 215-13L Sh 9045 minutes

Question - 1
Frequency Sort

Given an array of n item values, sort the array in ascending order, first by the frequency of each value, then by the values themselves.

Example
n=6
items = [4, 5, 6, 5, 4, 3]

There are 2 values that occur once: [3, 6].


There are 2 values that occur twice: [4, 4, 5, 5].
The array of items sorted by frequency and then by value in ascending order is [3, 6, 4, 4, 5, 5]

Function Description
Complete the function itemsSort in the editor below.

itemsSort has the following parameter(s):


int items[n]: the array to sort

Returns
int[n]: the sorted array

Constraints
1 ≤ n ≤ 2 × 105
1 ≤ items[i] ≤ 106

Input Format for Custom Testing


Sample Case 0
Sample Input 0

STDIN Function
----- --------
5 → items[] size n = 5
3 → items = [3, 1, 2, 2, 4]
1
2
2
4

Sample Output 0

1
3
4
2
2

Explanation

frequency of 1: [1], [3], [4]

1/3
frequency of 2: [2, 2]

Sort the array by frequency and then by value, ascending.


Sample Case 1

Question - 2
Cheese

Problem Statement
Takahashi, who works for a pizza restaurant, is making a delicious cheese pizza for staff meals.
There are N kinds of cheese in front of him.
The deliciousness of the i-th kind of cheese is Ai​per gram, and Bi​grams of this cheese are available.
The deliciousness of the pizza will be the total deliciousness of cheese he puts on top of the pizza.
However, using too much cheese would make his boss angry, so the pizza can have at most W grams of cheese on top of it.
Under this condition, find the maximum possible deliciousness of the pizza.
Constraints
All values in input are integers.
1≤N≤3×10^5
1≤W≤3×10^8
1≤Ai≤10^9
1≤Bi≤1000

Input
Input is given from Standard Input in the following format:

N W
A1​B1​
A2 B2​
⋮⋮
AN​BN​

Output
Print the answer as an integer.

Sample Input 1

3 5
3 1
4 2
2 3

Sample Output 1

15

The optimal choice is to use 1 gram of cheese of the first kind, 2 grams of the second kind, and 2 grams of the third kind.
The pizza will have a deliciousness of 15.

Sample Input 2

4 100
6 2
1 5

2/3
3 9
8 7

Sample Output 2

100

There may be less than WW grams of cheese in total.

Sample Input 3

10 3141
314944731 649
140276783 228
578012421 809
878510647 519
925326537 943
337666726 611
879137070 306
87808915 39
756059990 244
228622672 291

Sample Output 3

2357689932073

3/3

You might also like