Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def partition(a, l, r):
- el = a[(l + r) // 2]
- i, j = l, r
- while i <= j:
- while a[i] < el:
- i += 1
- while a[j] > el:
- j -= 1
- if i >= j:
- break
- a[i], a[j] = a[j], a[i]
- if a[i] != el:
- i += 1
- if a[j] != el:
- j -= 1
- return j
- def order(a, k):
- l, r = 0, len(a) - 1
- while True:
- m = partition(a, l, r)
- if m == k:
- return a
- elif m > k:
- r = m
- else:
- l = m + 1
- def main():
- n, k = list(map(lambda x: int(x), sys.stdin.readline().split()))
- max_wv, w, v, mb_ans = 0, [], [], None
- for _ in range(n):
- v_i, w_i = list(map(lambda x: int(x), sys.stdin.readline().split()))
- v.append(v_i), w.append(w_i)
- max_wv = max(max_wv, v_i / w_i)
- l, r = 0, max_wv
- check = None
- for i in range(47):
- m = (l + r) / 2
- check = order([(v[i] - m * w[i], i + 1) for i in range(n)], n - k)[n - k:]
- ans = sum([i[0] for i in check])
- if ans > 1e-7:
- l = m
- else:
- r = m
- sys.stdout.write(' '.join(map(str, [i[1] for i in check])))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement