prompt
string
response
string
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import itertools a=int(input()) aa=[int(i) for i in input().split()] b=int(input()) bb=[int(i) for i in input().split()] an=[] ans=1 for i in aa: for j in range(i): an.append(ans) ans+=1 for i in bb: print(an[i-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_left isDebug = False n = int(input()) a = [int(x) for x in input().split()] m = int(input()) q = [int(x) for x in input().split()] print(f'a={a}') if isDebug else '' l = len(a) for i in range(1, l): a[i] = a[i-1] + a[i] print(f'a={a}') if isDebug else '' for x in q: print(bisect_left(a...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def main(): n = int(input()) s = input().split() piles = [] total = 0 for i in range(n): piles += [(i+1)]*int(s[i]) m = int(input()) juicy = input().split() for i in range(m): index = int(juicy[i]) - 1 print(piles[index]) main()
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
'''input 5 2 7 3 4 9 3 1 25 11 ''' n = input() a = map(int,raw_input().split()) m = input() q = map(int,raw_input().split()) # Make cumulative list b = [-1] * n b[0] = a[0] for i in range(1,n): b[i] = b[i-1] + a[i] # Use binary search to play the game for j in range(m): low = 0 high = n-1 toCheck = q[j] while l...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
""" Satwik_Tiwari ;) . 25 june , 2020 - Thursday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, I...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int n, m, x, a[1000010]; vector<int> v, vv; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &x); a[x] = i; v.push_back(x); vv.push_back(x); } for (int i = 1; i < n; ++i) v[i] += v[i - 1]; scanf("%d", &m); while (m--) { ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) l = list(map(int,input().split())) m = int(input()) a = (list(map(int,input().split()))) d = {i:0 for i in a} l1 = a a = sorted(a) for i in range(1,n): l[i]+=l[i-1] i,j = 0,0 while j<m: if a[j]<=l[i]: d[a[j]]=i+1 j+=1 continue i+=1 for i in l1: print(d[i])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import bisect n = int(raw_input()) a= map(int,raw_input().split()) m=int(raw_input()) q= map(int,raw_input().split()) accu=0 for i in xrange(n): accu+=a[i] a[i]=accu for qi in q: print bisect.bisect_left(a,qi)+1
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) a = [1] + a for i in range(1, n+1): a[i] += a[i-1] P = a[-1]*[0] for i in range(n): for j in range(a[i], a[i + 1]): P[j - 1] = i + 1 for i in range(m): print(P[q[i] - 1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#_________________ Mukul Mohan Varshney _______________# #Template import sys import os import math import copy from math import gcd from bisect import bisect from io import BytesIO, IOBase from math import sqrt,floor,factorial,gcd,log,ceil from collections import deque,Counter,defaultdict from itertools import permu...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import bisect n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) ''' 循环实现的二分查找 ''' def search(seq, v, low, high): while low < high: mid = (low + high) // 2 if v <= seq[mid]: high = mid else: low = mid + 1 ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) arrn = list(map(int,input().split())) m = int(input()) arrm = list(map(int,input().split())) arr=[-1] for i in range(n): for j in range(arrn[i]): arr.append(i+1) for i in range(m): print(arr[arrm[i]])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int binary_search(int a[], int n, int x) { int low = 0, high = n - 1, result = -1, mid = 0; while (low <= high) { mid = low + (high - low) / 2; if (a[mid] == x) { return mid; } else if (a[mid] > x) { result = mid; high = mid - 1; } else...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj; vector<bool> visited; vector<bool> colors; vector<int> ans; vector<int> ans2; int n, k; int main() { int n; cin >> n; vector<int> v; int prev = 0; for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); v.push_back(temp + ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def binsrch(arr,low,hi,x): global bestans if low<=hi: if hi-low<5: for i in range(low,hi+1): if arr[i]>=x: bestans=i break else: mid=(low+hi)/2 if arr[mid]>=x: bestans=mid ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(raw_input()) a = map(int,raw_input().split()) n1 = int(raw_input()) q = map(int,raw_input().split()) b = [0] i = 0 for x in a: b.append(b[i] + x) i = i + 1 for x in q: m = 0 l = 1 r = n while(r > l): m = (r + l)>>1 if b[m] >= x: r = m elif b[m] < x: ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_right n=int(raw_input()) a=raw_input().split() for i in range(0,n): a[i]=int(a[i]) b=[] b.append(1) for i in range(0,n): b.append(b[len(b)-1]+a[i]) m=int(raw_input()) c=raw_input().split() for i in range(0,m): c[i]=int(c[i]) for i in range(0,m): # print b,c[i] p=bisect_right(b,c[i]) prin...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
d = dict() acc = 0 a__i= -1 n = int(input()) l = [int(x) for x in input().split()] for i in range(1,sum(l)+1): if acc>=i: d[i] = a__i else: acc += l[a__i+1] a__i +=1 d[i] = a__i n2 = int(input()) l1 = (int(x) for x in input().split()) for x in range(n2): print(d[next(l1)]+1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect n=int(input()) l=list(map(int,input().split())) c=int(input()) a=list(map(int,input().split())) s=[] t=1 r=0 for i in range(0,n): s.append(t) t=t+l[i] r=r+l[i] s.append(r) for i in range(0,c): m=bisect(s,a[i]) if m%2==0: print(m//2) else: print((m//2...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def ceil(a,k): l=0 h=len(a)-1 while l<h: mid=l+(h-l)//2 if a[mid]>=k: h=mid else: l=mid+1 return l+1 n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) sum=0 for i in range(n): sum+=a[i] a[i]=sum # print...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { long int n, m, c = 0, d = 0; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { cin >> c; d += c; a.push_back(d); } c = 0; cin >> m; int b[m]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < m; i++) { if (b[i...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
raw_input() a = map(int,raw_input().split()) raw_input() q = map(int,raw_input().split()) m = 0 for i in range(len(q)): q[i] = (q[i],i) q.sort() ans = [0]*len(q) i = 0 s = 0 for j in range(len(a)): s = s + a[j] while i<len(q) and q[i][0]<=s: ans[q[i][1]] = j i = i + 1 for x in ans: print x+1...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) arr = list(map(int,input().split(" "))) m = int(input()) arr2 = list(map(int,input().split(" "))) ans = [] for i in range(n): ans += [i]*arr[i] for j in range(m): print(ans[arr2[j]-1]+1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int save[100005]; int sum[100005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> save[i]; sum[0] = 0; for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + save[i]; int Q; cin >> Q; while (Q--) { int x; cin >> x; printf("%d\n", l...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100001]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int sum[100001]; sum[1] = a[1]; for (int i = 2; i <= n; i++) { sum[i] = sum[i - 1] + a[i]; } int m; cin >> m; int b[100001]; for (int i = 1; i <= m; ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_left,bisect n = int(input()) b = list(map(int,input().split())) s =0 t=[] for i in b: s+=i t.append(s) input() for j in map(int,input().split()): print(bisect_left(t,j)+1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import sys, math def rs(): return sys.stdin.readline().strip() def ri(): return int(sys.stdin.readline().strip()) def ras(): return list(sys.stdin.readline().strip()) def rai(): return map(int,sys.stdin.readline().strip().split()) def raf(): return map(float,sys.stdin.readline().strip().split()) ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) a = [int(i) for i in input().split()] ans = [] i = 1 for elem in a: while elem > 0: ans.append(i) elem -= 1 i+=1 m = int(input()) b = [int(i) for i in input().split()] for elem in b: print(ans[elem-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) li = [] k = 1 for i in input().split(): x = [k] * int(i) k += 1 li.extend(x) m = int(input()) for i in input().split(): print(li[int(i) - 1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[100001], hash[1000001], m, q; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &arr[i]); int st = 1, end = 0; for (int i = 0; i < n; i++) { end = end + arr[i]; for (int j = st; j <= end; j++) hash[j] = i + 1; st = end + ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
# You lost the game. n = int(input()) A = list(map(int, input().split())) m = int(input()) Q = list(map(int, input().split())) s = sum(A) T = [0 for _ in range(s)] c = 0 for i in range(n): for j in range(A[i]): T[c] = i + 1 c += 1 for i in range(m): print(T[Q[i]-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def acc_sum(array): for i in xrange(1, len(array)): array[i] += array[i-1] def bin_search(e, array, l, r): middle = (l+r)//2 if array[middle] == e: return middle+1 if l >= r: return r+1 if array[middle] < e: return bin_search(e, array, middle+1, r) return bin_search(e, array, l,...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
# from sys import stdin fn = input def get_closest_binary(num, l): if num > l[-1]: return l[-1] elif num < l[0]: return 0 else: m = 0 ma = len(l) - 1 while ma - m > 1: if num > l[m + ((ma - m) // 2)]: m += ((ma - m) // 2) else...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) piles = list(map(int, input().split())) m = int(input()) worms = [] i = 1 for j in list(map(int, input().split())): worms.append([i, j]) i += 1 worms.sort(key=lambda x: x[1]) k, i, tag = 0, 0, 0 sum_worms = 0 while k < n and tag == 0: sum_worms += piles[k] while worms[i][1] <= sum_worm...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n=int(input()) x=list(map(int,input().split())) m=int(input()) y=list(map(int,input().split())) l=[0] a=1 for i in x: j=i while(j>0): l.append(a) j-=1 a+=1 for i in y: print(l[i])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import math from collections import defaultdict, Counter, deque INF = float('inf') def gcd(a, b): while b: a, b = b, a%b return a def isPrime(n): if (n <= 1): return False i = 2 while i ** 2 <= n: if n % i == 0: return False i += 1 return True def vars(): return map(int, input().split()) def arr...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_left n=int(input()) s=list(map(int,input().split())) m=int(input()) p=list(map(int,input().split())) k=[0]*(n+1) for i in range(1,n+1): k[i]=k[i-1]+s[i-1] for i in p: print(bisect_left(k,i))
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; void zuka() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool isPrime(long long x) { if (x == 2) return true; else if (x == 1) return false; else { for (int i = 2; i * i <= x; i++) { if (x % i == 0) { return false; } ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) l = [] r = 1 for i in input().rstrip().split(): l += [r]*int(i) r += 1 input() for j in input().rstrip().split(): print(l[int(j)-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from sys import stdin, stdout def binary_search(array, target): l = 0 r = len(array) - 1 while l < r: mid = (l + r) // 2 if array[mid] < target: l = mid + 1 elif array[mid] > target: r = mid else: return mid return r def main(): ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int pos[100010]; pos[0] = 0; for (int i = 0; i < n; i++) { int buf; scanf("%d", &buf); pos[i + 1] = pos[i] + buf; } int m; scanf("%d", &m); for (int i = 0; i < m; i++) { int worm; scanf("%d", &worm);...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import java.io.*; public class Main { public static void main(String args[])throws IOException { BufferedReader obj=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(obj.readLine()); String temp[]=obj.readLine().split(" "); int arr[]=new int[n]; int b[]=new int[20000000]; int z=0; for(...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
/** * Author : Descifrador */ import java.io.*; import java.util.*; public class Demo { static MyScanner sc; static final Random random = new Random(); static final int[] dr4 = {1, 0, -1, 0}; static final int[] dc4 = {0, 1, 0, -1}; static final int[] dr8 = {1, 1, 0, -1, -1, -1, 0, 1}; st...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n, p, m, w = int(input()), list(map(int, input().split())), int(input()), sorted(enumerate(map(int, input().split())), key = lambda x: x[1]) ans, pos = [-1] * m, [0, 0] for i, c in w: while pos[0] + p[pos[1]] < c: pos[0] += p[pos[1]] pos[1] += 1 ans[i] = pos[1] + 1 print(*ans, sep = '\n')
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def lower_bound(p,v): l = 0 r = len(p)-1 while(r >= l): m = (r-l)/2 + l if (p[m]>v): r = m-1 elif (p[m] == v): return m else: l = m+1 return l n = int(raw_input()) p = map(int,raw_input().split()) for i in xrange(1,len(p)): p[i]= p[i-1]+p[i] m = int(raw_input()) re...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import * def read(): return (int(x) for x in input().split()) input() a = [0] for x in read(): a.append(a[-1] + x) input() for x in read(): print(bisect_left(a, x))
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
a = input() x = [int(x) for x in input().split()] s = 0 l = [] b = input() y = [int(y) for y in input().split()] for i in x: s = s + i l.append(s) ind = 0 w = [] for j in range(1 , s + 1): if j > l[ind]: ind += 1 w.append(ind + 1) for k in y: print(w[k - 1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(raw_input()) worms = [int(x) for x in raw_input().split()] m = int(raw_input()) juicy = [int(y) for y in raw_input().split()] somas_parciais = [worms[0]] soma=worms[0] for i in worms[1:]: soma+=i somas_parciais.append(soma) def bsearch(k,n): left = 0 right = n while(left<=right): mid = (left+right)...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import math import random import itertools import collections import sys import time import fractions import os import functools import bisect def timer(f): def tmp(*args, **kwargs): t = time.time() res = f(*args, **kwargs) print("Время выполнения функции: %f" % (time.time()-t)) re...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
# your code goes here # your code goes here import sys n=int(sys.stdin.readline()); a=map(int,sys.stdin.readline().split(" ")); m=int(sys.stdin.readline()) b=map(int,sys.stdin.readline().split(" ")); sol=[] sol.append(0) for i in range(0,n): for j in range(0,a[i]): sol.append(i+1) for i in range(0,m): ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n=int(input()) x=[] x=input().split() ps=[] ps.append(int(x[0])) for i in range(1,n): ps.append(int(x[i])+ps[i-1]) m=int(input()) x=input().split() for i in range(m): b,l=0,n-1 while(b<l): mid=(b+l)//2 if(int(x[i])<=ps[mid]): l=mid else: b=mid+1 print(l+1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n_piles = int(input()) s_piles = input().split(" ") piles = [] for i in range(n_piles): pile = [i+1]*int(s_piles[i]) piles.extend(pile) n_search = int(input()) s_search = input().split(" ") for i in range(n_search): print(piles[int(s_search[i])-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) aa = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) a = [1, aa[0]] for i in range(1, n): a.append(a[-1] + aa[i]) for qq in q: l = 0 r = n while r - l > 1: if qq <= a[(l+r)//2]: r = (l+r)//2 else: l = (l+r)//...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_left n = int(input()) a = list(map(int, input().rstrip().split())) m = int(input()) q = list(map(int, input().rstrip().split())) li = [0] * (n + 1) for i in range(n): li[i + 1] = li[i] + a[i] for x in q: print(bisect_left(li, x)) # print(li)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int arr[100000]; int main() { ios_base::sync_with_stdio(false); int n, sum = 0, count = 1, lower = 1, upper = 0; cin >> n; for (int x = 0; x < n; x++) cin >> arr[x]; for (int y = 0; y < n; y++) sum = sum + arr[y]; int sumarr[sum]; for (int z = 0; z < n; z++) {...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n=int(input()) a=list(map(int,input().split())) m=int(input()) q=map(int,input().split()) d=dict() a0=1 for i in range(n): for k in range(a0,a0+a[i]): d[k]=i+1 a0+=a[i] for u in q: print(d[u])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a; vector<int> q; void read() { cin >> n; int ai; cin >> ai; a.push_back(ai); for (int i = 1; i < n; ++i) { cin >> ai; a.push_back(a[i - 1] + ai); } cin >> m; for (int i = 0; i < m; ++i) { int qi; cin >> qi; q.push_b...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from sys import stdin, stdout import timeit class IndexedPile: def __init__(self, first, last, index): self.first = first self.last = last self.index = index def __repr__(self): return "<IndexedPile (%s,%s,%s)" % (self.first, self.last, self.index) def is_compared(self, value): if value...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def LowerBound(A, key): left = -1 right = len(A) while right > left + 1: middle = (left + right) // 2 if A[middle] >= key: right = middle else: left = middle return right n = int(input()) a = list(map(int, input().split())) m = int(input()) q = l...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
a = int(input()) heap = [int(x) for x in input().split()] b = int(input()) sochnyi = [int(x) for x in input().split()] arr = [] for i in range(len(heap)): for j in range(heap[i]): arr.append(i) for i in sochnyi: print(arr[i-1]+1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from sys import stdin, stdout from bisect import bisect_left _ = int( stdin.readline() ) a = [0] + map( int, stdin.readline().split() ) _ = int( stdin.readline() ) q = map( int, stdin.readline().split() ) for i in xrange( 1, len(a) ): a[i] += a[i - 1] for x in q: stdout.write( str( bisect_left(a, x) ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
L1=[] input() r=1 for k in input().split(" "): L1+=[r]*int(k) r+=1 input() for j in input().split(" "): print(L1[int(j)-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; long long int a[1000008]; int main() { long long int x, y; cin >> x; a[0] = 0; for (int i = 1; i <= x; i++) { cin >> a[i]; } for (int i = 1; i <= x; i++) { a[i] += a[i - 1]; } cin >> y; for (int i = 0; i < y; i++) { long long int w; cin >> ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
nPilhasVermes = int(input()) nVermesPorPilha = input().split() nVermesSaborosos = int(input()) iVermeSaboroso = input().split() lista = [] for i in range(nPilhasVermes): for j in range(int(nVermesPorPilha[i])): lista.append(i+1) for i in range(nVermesSaborosos): print(lista[int(iVermeSaboroso[i]) - 1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) arr = [int(x) for x in input().split(" ")] m = int(input()) labels = [int(x) for x in input().split(" ")] buckets = [] for i, a in enumerate(arr): for _ in range(a): buckets.append(i) for q in labels: print(buckets[q - 1] + 1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, j = 1, t, a[1000002]; cin >> n; for (int i = 1; i <= n; i++) { cin >> t; while (t--) { a[j] = i; j++; } } cin >> m; while (m--) { cin >> t; cout << a[t] << endl; } return 0; }
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
__author__ = 'Devesh Bajpai' ''' https://codeforces.com/problemset/problem/474/B Solution: ''' def solve(n, worms_count, m, queries): for i in xrange(1, n): worms_count[i] += worms_count[i-1] result = list() for _m in xrange(0, m): query = queries[_m] start = 0 end =...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import java.io.*; import java.util.*; public class CodeF { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer. parseInt(br.readLine()); String []s=br. readLine().split(" "); int a[]=new ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def bsearch(lis, num): n=len(lis) first=0 last=n-1 while(first<=last): mid=(first+last)//2 if(lis[mid]<=num<=lis[mid+1]): return mid elif(lis[mid]>num): last=mid-1 elif(lis[mid+1]<num): first=mid+1 n=int(input()) nums=list(map(int,inpu...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) heap = list(map(int, input().split())) t = int(input()) test = list(map(int, input().split())) res = [0] for i in range(n): res += [i + 1] * heap[i] for i in range(t): print(res[test[i]])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; long long int d[1000010] = {0}; int main() { long long int j = 0, n, a[100010], i, m, t, sum = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; while (a[i]--) { d[++j] = i + 1; } } cin >> m; for (i = 0; i < m; i++) { cin >> t; cout <...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) d = {} _min = 1 pile = 1 for e in map(int, input().split()): for i in range(_min, _min+e+1): d[i] = pile _min += e pile += 1 m = int(input()) for q in map(int, input().split()): print(d[q])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int ary[1000 * 1000 + 100]; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n; int k = 1; for (int i = 1; i <= n; i++) { int tmp; cin >> tmp; for (int j = k; j < k + tmp; j++) { ary[j] = i; } k += tmp; } cin >> m; fo...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, m1; cin >> n; long long a[n + 1]; a[0] = 0; for (long long i = 1; i <= n; i++) { cin >> t; a[i] = a[i - 1] + t; } cin >> m1; for (long long i = 0; i < m1; i++) { cin >> t; long long m = n / 2, l = 1, r = n; wh...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def findq(num,arr): start = 0 end = len(arr)-1 while (start < end): mid = (start + end)/2 #print "mid",mid if(num > arr[mid] and num <= arr[mid + 1] ): return mid+1 elif(num > arr[mid] and num > arr[mid+1]): start = mid else: end = mid n = input() a = [None]*n anew = [None]*n as1 = raw_input()...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#!/usr/bin/env python3 import atexit import io import sys import bisect _I_B = sys.stdin.read().splitlines() input = iter(_I_B).__next__ _O_B = io.StringIO() sys.stdout = _O_B @atexit.register def write(): sys.__stdout__.write(_O_B.getvalue()) def main(): dp=dict() n=int(input()) a=list(map(int,inpu...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; long long int solve(long long int val); long long int arr[100005], n; int main() { long long int i, j, m, sum, x, ss = 0, y; cin >> n; for (i = 0; i < n; i++) { cin >> x; ss += x; arr[i] = ss; } cin >> m; for (i = 0; i < m; i++) { cin >> y; l...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def binarry_search_interval(array, num): i = 0 j = len(array) while i <= j: mid = (i + j) // 2 if array[mid] == num: return mid + 1 if array[mid] > num: j = mid - 1 else: i = mid + 1 return i+1 def solution(): n = int(input()) ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int buscabin(int x, int v[], int n) { int ini = 1, meio, fim = n; while (ini <= fim) { meio = (ini + fim) / 2; if (x <= v[meio] && x > v[meio - 1]) return meio; if (v[meio] > x) fim = meio - 1; else ini = meio + 1; } } int main() { int n,...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); int[] sc = new int[100010]; int n, m, x, index; n = cin.nextInt(); sc[0] = cin.nextInt(); for (int i = 1; i < n; ++i) sc[i] = sc[i-1]...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_left n = int(input()) a = list(map(int, input().split(' '))) for i in range(1, len(a)): a[i] += a[i-1] m = int(input()) qs = list(map(int, input().split(' '))) for q in qs: print(bisect_left(a, q)+1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
ans = list() def solve(): n=int(input()) arr=[int(x) for x in input().split()] m=int(input()) brr=[int(x) for x in input().split()] for i in range(n): x=int(arr[i]) #print(x) for j in range(x): ans.append(i+1) #print(ans) for i in range(m): ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n=int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) z=[] for i in range(n): for j in range(a[i]): z.append(i+1) for i in q: x=z[i-1] print(x)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) heap = list(map(int, input().split(' '))) m = int(input()) nums = list(map(int, input().split(' '))) originNums = nums.copy() nums.sort() heaps = [] previousNumber = 1 for i in range(n): heaps.append( (previousNumber, previousNumber + heap[i] - 1) ) previousNumber = previousNumber + heap[i] ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n_piles = int(input()) piles = list(map(int, input().split())) n_juicy = int(input()) juicy = list(map(int, input().split())) # worms = list() # index = 0 # for p in piles: # if len(worms) == 0: # worms.append(p) # index += 1 # else: # worms.append(worms[index-1]+p) # index ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n=int(input()) l=list(map(int,input().strip().split())) m=int(input()) arr=list(map(int,input().strip().split())) a=[] for i ,x in enumerate(l): for _ in range(x): a.append(i+1) for j in arr: print(a[j-1])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
from bisect import bisect_left x = int(input()) nums = list(map(int, input().split())) #print(nums) for i in range(1, x): nums[i]+= nums[i-1] y = int(input()) nums2 = list(map(int, input().split())) for i in range(y): res = bisect_left(nums,nums2[i])+1 print(res) #print(nums)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
def binarySearch(arr, l, r, x): while l <= r: mid = l + int((r - l) / 2); if r==0: return 0 if arr[mid] >= x and arr[mid-1]<x: return mid elif arr[mid] > x: r = mid - 1 else: l = mid + 1 return 0 n = int(input()) list1 =list...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, e, s = 0, mid; cin >> n; e = n - 1; int x[n]; for (int i = 0; i < n; i++) { cin >> x[i]; if (i != 0) x[i] += x[i - 1]; } cin >> m; int y[m]; for (int i = 0; i < m; i++) cin >> y[i]; for (int i = 0; i < m; i++) { s = 0; ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) worms = {} prev = 1 for i in range(n): for j in range(prev, prev + a[i]): worms[j] = i + 1 prev += a[i] for x in q: print(worms[x])
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) ai = input().split() m = int(input()) qi = input().split() ai[0] = int(ai[0]) for i in range(1, n): ai[i] = int(ai[i]) + ai[i - 1] for i in range(m): qi[i] = int(qi[i]) left = 0 right = n while right > left: mid = (right + left) // 2 if qi[i] < ai[mid]: ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n = int(input()) arr = list(map(int, input().split()[:n])) for i in range(1, n): arr[i] += arr[i - 1] def b_search(start, end, a): if start > end: return (start + end + 1) // 2 mid = (start + end) // 2 if arr[mid] == a: return mid elif arr[mid] > a: return b_search(start, m...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
na = int(input()) a = list(map(int,input().split())) qa = int(input()) q = list(map(int,input().split())) beg = 0 end = 0 ans = [] def bsl(beg,end,x,lo) : global ans if beg == end : if ans[beg] <= x and ans[beg] > ans[lo] : return beg return lo mid = (beg+end)//2 if ans[mid...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int piles; cin >> piles; vector<int> worms(piles + 1); worms[0] = 1; for (int i = 0; i < piles; ++i) { cin >> worms[i + 1]; worms[i + 1] += worms[i]; } int juicy_worms; cin >> juicy_worms; for (int i...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import bisect n=int(input()) w=list(map(int, input().strip().split())) m=int(input()) q=list(map(int, input().strip().split())) r = [0] for i in w: r.append(i+r[-1]) r=r[1:] for k in range(0, m): print(bisect.bisect_left(r, q[k]) + 1)
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
/** * Created by Влад on 13.10.2014. */ import java.io.*; import java.util.*; public class cf_b { public static void main(String args[]){ Scanner in=null; PrintWriter out=null; try{ in=new Scanner(System.in); out=new PrintWriter(System.out); int n=in.ne...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
#include <bits/stdc++.h> using namespace std; int a[600006]; int main() { int n, i, j, k, pos, m, p, q, s, sm = 0, hi, lo, mid; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &s); sm += s; a[i] = sm; } scanf("%d", &k); for (j = 0; j < k; j++) { cin >> q; if (q < a[0]) print...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
z,zz=input,lambda:list(map(int,z().split())); szz,dgraphs,mod=lambda:sorted(zz()),{},10**9+7 from string import * from collections import * from queue import * from sys import * from collections import * from math import * from heapq import * from itertools import * from bisect import * from collections import Counter ...
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
n=int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) b=[] for i in range(n): b+=[i+1]*a[i] for i in q: print(b[i-1], end = '\n')
Problem: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled wi...
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { static int n,m, pile[], juice[]; static boolean isPossible = true; public static void main(String[] args) { Scanner ...