-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathPriyanka and Toys.py
51 lines (38 loc) · 1.17 KB
/
Priyanka and Toys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Problem Statement
Little Priyanka visited a kids' shop. There are N toys and their weight is represented by an array W=[w1,w2,…,wN]. Each
toy costs 1 unit, and if she buys a toy with weight w′, then she can get all other toys whose weight lies between
[w′,w′+4] (both inclusive) free of cost.
Input Format
The first line contains an integer N i.e. number of toys.
Next line will contain N integers, w1,w2,…,wN, representing the weight array.
Output Format
Minimum units with which Priyanka could buy all of toys.
"""
__author__ = 'Danyang'
class Solution(object):
def solve(self, cipher):
"""
main solution function
:param cipher: the cipher
"""
A = sorted(cipher)
cur = -5
cnt = 0
for a in A:
if cur + 4 < a:
cur = a
cnt += 1
return cnt
if __name__ == "__main__":
import sys
f = open("0.in", "r")
# f = sys.stdin
solution = Solution()
n = int(f.readline().strip())
# construct cipher
cipher = map(int, f.readline().strip().split(' '))
# solve
s = "%s\n" % (solution.solve(cipher))
print s,