Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
474_B. Worms
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 with number...
2
8
import sys input = sys.stdin.readline def main(): int(input()) heaps = list(map(int, input().split())) sum = 0 i = 0 while i < len(heaps): heaps[i] = sum + heaps[i] sum = heaps[i] i += 1 int(input()) es = list(map(int, input().split())) for e in es: prin...
PYTHON3
474_B. Worms
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 with number...
2
8
def busca_binaria(lista,numero): comeco = 0 fim = len(lista) while True: meio = (comeco+fim) / 2 if comeco > fim: break if lista[meio] == numero: return meio + 1 elif lista[meio] < numero: comeco = meio + 1 elif lista[meio] > numero: fim = meio - 1 return comeco + 1 n = int(raw_input()) pil...
PYTHON
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; long long int n, m, a[100001], b[100001], q[100001]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) b[i] = a[i] + b[i - 1]; cin >> m; for (int i = 0; i < m; i++) { long long int first = 1, last = n, mid, ans = 0; ...
CPP
474_B. Worms
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 with number...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import java.util.StringTokenizer; import java.util...
JAVA
474_B. Worms
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 with number...
2
8
# -*- coding: utf-8 -*- #!/usr/bin/env python n = int(raw_input()) worms = map(int, raw_input().split(' ')) m = int(raw_input()) q = map(int, raw_input().split(' ')) l = [0] z= 1 for i in worms: l += i*[z] z += 1 for i in q: print l[i]
PYTHON
474_B. Worms
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 with number...
2
8
def binarySearch (arr, l, r, x): if r >= l: mid = l + (r - l)//2 if arr[mid] == x: return mid elif arr[mid] > x: return binarySearch(arr, l, mid-1, x) else: return binarySearch(arr, mid + 1, r, x) else: return r+1 #main n=int(input()) l1=list(map(int,input().split())) m=int(input()) l2=...
PYTHON3
474_B. Worms
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 with number...
2
8
r=int(input()) ra=[int(x) for x in input().split()] j=int(input()) jf=[int(x) for x in input().split()] dp=[0]*sum(ra) k=1 i=0 j=0 for f in range(len(dp)): dp[f]=k j+=1 if j==ra[i]: j=0 i+=1 k+=1 for y in range(len(jf)): #print("hi") print(dp[jf[y]-1])
PYTHON3
474_B. Worms
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 with number...
2
8
import sys n=int(input()) a=[int(i) for i in input().split(" ")] b=[] k=0 for i in range(n): k+=1 for j in range(a[i]): b.append(k) m=int(input()) a=[int(i) for i in input().split(" ")] for i in a: print(b[i-1])
PYTHON3
474_B. Worms
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 with number...
2
8
def binarysearch(a,b): l=0 h=len(a)-1 while(l<=h): mid=(l+h)//2 if a[mid]==b: return mid elif a[mid]<b: l=mid+1 continue else: if a[mid]>b: h=mid-1 continue else: return l t=int(input(...
PYTHON3
474_B. Worms
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 with number...
2
8
import sys input=sys.stdin.buffer.readline t=int(input()) arr=list(map(int,input().split())) ans=[] c=0 for x in arr: c+=x ans.append(c) #print(ans) n=int(input()) arr2=list(map(int,input().split())) for x in arr2: #break l=0 u=t-1 z=0 while l<=u: mid=(l+u)//2 #print(l,u,mid) if ans[mid]==x: print(mid+...
PYTHON3
474_B. Worms
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 with number...
2
8
def binarySearch(a,q, start, end): mid=int (start+int((end-start)/2)) if a[mid]>=q and a[mid-1] < q: return int(mid+1) elif a[mid]>q: return int(binarySearch(a,q,start,mid)) elif a[mid]<q: return int(binarySearch(a,q,mid+1,end)) def main(): n = int(input()) a = [0]*n ip = [int(i) for i in input().split()]...
PYTHON3
474_B. Worms
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 with number...
2
8
# For taking integer inputs. import math def inp(): return(int(input())) # For taking List inputs. def inlist(): return(list(map(int, input().split()))) # For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings a...
PYTHON3
474_B. Worms
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 with number...
2
8
n = int(input()) li = [] index = 1 for i in map(int, input().split()): li += [index] * i index +=1 m = int(input()) for query in map(int, input().split()): print(li[query -1])
PYTHON3
474_B. Worms
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 with number...
2
8
################################## # author: Qzaro # # created: 2019-08-23 20:38:35 # ################################## from heapq import merge import datetime import math def clock(): print(datetime.datetime.now()) input();a=([int(x) for x in input().split()]) input();b=([int(x) for x in input(...
PYTHON3
474_B. Worms
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 with number...
2
8
n = int(input()) pile = [int(x) for x in input().split()] m = int(input()) temp = [int(x) for x in input().split()] temp[0] = [temp[0], 0] spile = [pile[0]] for i in range(1, n): spile.append(spile[-1]+pile[i]) for i in range(1, m): temp[i] = [temp[i], i] temp = sorted(temp, key=lambda x: x[0]) #print(temp) cnt...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; public class B { public static void main(String[] ...
JAVA
474_B. Worms
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 with number...
2
8
import sys def search(Max,new,num): if new[0]>num: return 1 Min =0 Mid = int((Max+Min)/2) while Min<=Max: if new[Mid]==num: return Mid+1 break elif new[Min]==num: return Min+1 break elif new[Mid]<num and new[Mid+1]>num: return Mid+2 break elif new[Mid]<num: Min=Mid+1 else: Max=M...
PYTHON
474_B. Worms
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 with number...
2
8
def I(): return(list(map(int,input().split()))) n=int(input()) x=I() m=int(input()) q=I() arr=[0]*(n+1) arr[0]=x[0] for i in range(n-1): arr[i+1]=arr[i]+x[i+1] for i in range(m): l=0 r=n-1 while(l<=r): mid=(r-l)//2+l if arr[mid]<q[i]:l=mid+1 else:r=mid-1 print(l+1)
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int a[10000001], n, i, m, k = 0, x, j; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> x; for (j = k + 1; j <= k + x; j++) a[j] = i; k = k + x; } cin >> m; while (m-- > 0) { cin >> x; cout << a[x] << endl; } }
CPP
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int ara[100005]; int main() { int i, j, k; int n, q; int low, high, mid, ans; cin >> n; for (i = 0, j = 1; i < n; ++i) { cin >> k; ara[j] = ara[j - 1] + k; j++; } cin >> q; while (q--) { cin >> k; low = 1; high = n; ans = -1; ...
CPP
474_B. Worms
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 with number...
2
8
N = int(input()) A_arr = list(map(int, input().split())) M = int(input()) Q_arr = list(map(int, input().split())) arr2 = [] arr2.append(-1) sum_cool = sum(A_arr) curpos = 0 for i in range(N): for j in range(A_arr[i]): arr2.append(i) #handle everything 0..n-1 and output with +1 in end #print(arr2,len(arr2)) for i...
PYTHON3
474_B. Worms
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 with number...
2
8
import math from bisect import bisect_left,bisect,bisect_right from itertools import accumulate import math def find_ge(a, x): 'Find leftmost item greater than or equal to x' i = bisect_left(a, x) if i != len(a): return i st='' def func(n,l1): return(find_ge(l1,n)+1) for _ in range(1):...
PYTHON3
474_B. Worms
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 with number...
2
8
# -*- coding: utf-8 -*- """ Created on Mon May 18 08:46:25 2020 @author: Harshal """ import bisect n=int(input()) arr=list(map(int,input().split())) q=int(input()) arr2=list(map(int,input().split())) for i in range(1,n): arr[i]+=arr[i-1] for i in arr2: print(bisect.bisect_left(arr,i)+1)
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); scanf("%d", &m); int pile[n + 1]; pile[0] = 0; for (int i = 1; i <= n; i++) { pile[i] = a[i - 1] + pile[i - 1]; } int worm[m]; for (int i = 0; i < m; ...
CPP
474_B. Worms
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 with number...
2
8
input() array =[] c =1 for item in input().split(): array+=[c]*int(item) c+=1 input() for item in input().split(): print(array[int(item)-1])
PYTHON3
474_B. Worms
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 with number...
2
8
n = int(input()) a = list(map(int,input().split())) c = [] s = 0 for x in a: s += x c.append(s) m = int(input()) q = list(map(int,input().split())) for x in q: l = 1 r = n while l < r-1: m = (l+r)//2; if c[m-1] < x: l = m else: r = m if c[l-1] >= x...
PYTHON3
474_B. Worms
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 with number...
2
8
import sys f = sys.stdin n = int(f.readline()) a = map(int, f.readline().split()) flags = list() for i, x in enumerate(a): for _ in range(x): flags.append(i+1) m = int(f.readline()) queries = map(int, f.readline().split()) for q in queries: print(flags[q-1])
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 0; const long long inf = 1e15 + 7; const long double eps = 1e-9; const long double PI = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n]; int mini[n], mx[n]; int mn = 0, mxn = 0; for (int i ...
CPP
474_B. Worms
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 with number...
2
8
def func(n): l = list(map(int,input().split())) juicy = int(input()) juicy_in = list(map(int,input().split())) dictionary = {} j = 1 k = 1 for i in l: for i in range(i): dictionary[j] = k j += 1 k += 1 for i in juicy_in: print(dictionary...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.util.*; public class b { public static void main(String[] args) { int[] res = new int[1000001]; Scanner input = new Scanner(System.in); int n = input.nextInt(); int at = 0; for(int i = 0; i<n; i++) { int a = input.nextInt(); for(int j = 0; j<a; j++) res[at++] = i+1; ...
JAVA
474_B. Worms
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 with number...
2
8
import java.util.*; public class Main{ public static void main(String[]args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for(int in=0;in<n;in++){ arr[in]=sc.nextInt(); } for(int is=1;is<n;is++){ arr[is]=arr[is]...
JAVA
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> int main() { int n; std::cin >> n; int a[n]; std::vector<int> moltiplicatori; for (int i = 1; i <= n; i++) { int t; std::cin >> t; for (int j = 0; j < t; j++) moltiplicatori.push_back(i); } int m; std::cin >> m; for (int i = 0; i < m; i++) { int k; std::cin...
CPP
474_B. Worms
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 with number...
2
8
""" def wormsy(n,piles,m,worms): for w in worms: pile_no=0 current=0 for pile in piles: current+=pile pile_no+=1 if current>=w: print(pile_no) break else: continue return """ """ def binary(x,...
PYTHON3
474_B. Worms
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 with number...
2
8
# Worms def fst(tuple): return tuple[0] def snd(tuple): return tuple[1] n = input() piles = list(map(int, input().split())) w = input() worms = list(map(int, input().split())) piles[0] = (1, piles[0]) ans = [0 for i in range(10**6 + 2)] for i in range(len(piles)): if i > 0: size = piles[i] ...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.io.*; import static java.lang.Math.*; import java.util.Arrays; public class Mainl { static PrintWriter out = new PrintWriter(System.out); static Scan in = new Scan(); static int bs(int[] a1, int[] a2, int L, int R, int key){ while (L <= R){ int mid = L + ((R -...
JAVA
474_B. Worms
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 with number...
2
8
n = int(input()) p = list(map(int, input().split())) m = int(input()) t = list(map(int, input().split())) k = 0 for x in range(len(p)): p[x] +=k k = p[x] for key in t: beg = -1 end = len(p) if end - beg <4: for l in range(beg, end+1): if l >= 1: if key<= p[l] and key>p[l-1]: print(l+1) else: ...
PYTHON3
474_B. Worms
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 with number...
2
8
from math import * from copy import * from string import * # alpha = ascii_lowercase from random import * from sys import stdin from sys import maxsize from operator import * # d = sorted(d.items(), key=itemgetter(1)) from itertools import * from collections import Counter # d = dict(Counter(l)) import math def...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.util.*; import java.io.*; public class spoj { public static void main(String[] args) { // BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); // int n=Integer.parseInt(br.readLine()); Scanner sc=ne...
JAVA
474_B. Worms
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 with number...
2
8
def binarySearch(nums,target): if len(nums) == 0: return -1 left, right = 0, len(nums) while left < right: mid = left + (right - left) // 2 if nums[mid] > target: right = mid else: left = mid + 1 return left n = int(input()) a = list(map(int,input...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.util.*; public class prob { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); int[] pile = new int[num]; int count = 0; for(int i = 0; i < num; i++) { pile[i] = scan.nextInt()+count; count = pile[i]; } ...
JAVA
474_B. Worms
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 with number...
2
8
def busca_binaria(elemento, lista): """ Busca Binaria Em Pilhas :returns: Indice da pilha em que o elemento se encontra """ inicio = 0 fim = len(soma_acumulada)-1 resultado = -1 while inicio <= fim: meio = inicio + (fim-inicio)/2 if soma_acumulada[meio] ...
PYTHON
474_B. Worms
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 with number...
2
8
def binary_search(list, goal, start, end): i = int((start + end) / 2) if accum[i] == goal: return i + 1 elif accum[i] < goal: return binary_search(list, goal, i, end) else: if i == 0 or (i > 0 and accum[i-1] < goal): return i + 1 else: return binar...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Javademo { static class FastReader { BufferedReader br; StringTokenizer st; public Fa...
JAVA
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int n, p[100002], m, w; int main() { scanf("%d%d", &n, &p[0]); for (int i = 1; i < n; i++) { scanf("%d", &p[i]); p[i] += p[i - 1]; } scanf("%d", &m); while (m--) { scanf("%d", &w); int lo = 0, hi = n - 1, mid; while (hi > lo) { mid = (hi ...
CPP
474_B. Worms
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 with number...
2
8
n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) d = {} k = 0 for i in range(n): for j in range(a[i]): k += 1 d[k] = i+1 for i in q: print(d[i]) # print(n, a, m ,q, d)
PYTHON3
474_B. Worms
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 with number...
2
8
from bisect import * n=int(input()) a=[int(i) for i in input().split()] p=[0] for i in a: p.append(i+p[-1]) input() for i in input().split(): print(bisect_left(p,int(i)))
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m, x, pos = 0; vector<int> v; cin >> n; for (int i = 0; i < n; i++) { cin >> x; v.push_back(pos + x); pos += x; } cin >> m; for (int j = 0; j < m; j++) { cin >> x; vector<int>::iterato...
CPP
474_B. Worms
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 with number...
2
8
L=[] input() r=1 for k in input().split(" "): L+=[r]*int(k) r+=1 input() for j in input().split(" "): print(L[int(j)-1])
PYTHON3
474_B. Worms
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 with number...
2
8
x = int(input()) a = [0] b = [int(x) for x in input().split()] for i in range(x): for j in range(b[i]): a.append(i + 1) x = int(input()) b = [int(x) for x in input().split()] for i in range(x): print(a[b[i]])
PYTHON3
474_B. Worms
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 with number...
2
8
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...
PYTHON3
474_B. Worms
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 with number...
2
8
def low(brr,c,l,r): mid=int (l+int((r-l)/2)) if brr[mid]>=c and brr[mid-1]<c: return int(mid+1) elif brr[mid]>c: return int(low(brr,c,l,mid)) elif brr[mid]<c: return int(low(brr,c,mid+1,r)) n=int(input()) arr=list(map(int,input().split(" "))) srr=list(0 for i in range(n)) sr...
PYTHON3
474_B. Worms
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 with number...
2
8
n=int(input()) l=[] r=1 for k in input().split(): for j in range(int(k)): l.append(r) r+=1 q=input() for j in input().split(): print(l[int(j)-1])
PYTHON3
474_B. Worms
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 with number...
2
8
def findpile(worm, P, n): mid = n/2 first = 0 last = n while first != last: if worm > P[mid]: first = mid+1 mid = (first+last)/2 elif worm <= P[mid]: last = mid mid = (first+last)/2 ans = first+1 return ans ...
PYTHON
474_B. Worms
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 with number...
2
8
import java.util.Scanner; public class Main { private static Scanner sc; private static int[] data; public static void main(String[] args) { sc = new Scanner(System.in); int n = sc.nextInt(); data = new int[n]; int init = 0; for (int i = 0; i < n; i++) { init += sc.nextInt(); data[i] = init; ...
JAVA
474_B. Worms
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 with number...
2
8
__author__ = 'hamed1soleimani' import math input() p = input().split() input() q = input().split() worms = list(range(10 ** 6)) m = 0 for i in range(len(p)): for j in range(int(p[i])): worms[m] = i m += 1 for x in q: print(worms[int(x) - 1] + 1)
PYTHON3
474_B. Worms
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 with number...
2
8
from bisect import bisect_left n = int(input()) ls = list(map(int, input().split())) m = int(input()) vals = list(map(int, input().split())) nls = [ls[0]] for i in range(1, n): nls.append(nls[i-1] + ls[i]) # print(nls) for val in vals: ind = bisect_left(nls, val) print(ind+1)
PYTHON3
474_B. Worms
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 with number...
2
8
import sys def search(Max,new,num): if new[0]>num: return 1 Min =0 Mid = int((Max+Min)/2) while Min<=Max: if new[Mid]==num: return Mid+1 break elif new[Min]==num: return Min+1 break elif new[Mid]<num and new[Mid+1]>num: return Mid+2 break elif new[Mid]<num: Min=Mid+1 else: Max=M...
PYTHON
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; void fast() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int main() { fast(); const int N = 2e6 + 15; int n, m; cin >> n; int l = 0, r = 0, t; vector<int> a(N, 0); for (int i = 0; i < n; i++) { cin >> t; l = r + 1; r ...
CPP
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int i, n, m, q, index; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 1; i < n; i++) { a[i] = a[i - 1] + a[i]; } scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &m); int high, low, mi...
CPP
474_B. Worms
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 with number...
2
8
n=int(input()) a=[int(x) for x in input().split()] m=int(input()) q=[int(x) for x in input().split()] for i in range(1,n): a[i] += a[i-1] for num in q: l,r=0,n-1 while l<=r: mid = (l+r)//2 if a[mid] < num: l=mid+1 else: r=mid-1 print(l+1)
PYTHON3
474_B. Worms
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 with number...
2
8
import java.util.Scanner; public class Worms { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] bounds = new int[n + 1]; bounds[0] = 0; int sum = 0; for(int i = 1; i <= n; i++) { int pile =...
JAVA
474_B. Worms
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 with number...
2
8
from sys import stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] ch = [a[0]] for i in range(1, n): ch.append(a[i] + ch[i - 1]) m = int(stdin.readline()) b = map(int, stdin.readline().split()) mid = l = r = 0 for x in b: l = 0 r = n while l != r - 1: mid = (...
PYTHON3
474_B. Worms
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 with number...
2
8
from sys import stdin from bisect import bisect_left def main(): stdin.readline() x, a = 0, [] for y in map(int, stdin.readline().split()): x += y a.append(x) stdin.readline() for x in map(int, stdin.readline().split()): print(bisect_left(a, x) + 1) main()
PYTHON3
474_B. Worms
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 with number...
2
8
n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) t = [0] for idx, val in enumerate(a): for j in range(val): t.append(idx + 1) for val in q: print(t[val])
PYTHON3
474_B. Worms
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 with number...
2
8
n=int(input()) list=input().split() ans=dict() cnt=0 for i in range(n): for j in range(int(list[i])): cnt+=1 ans[cnt]=i+1 n=int(input()) list=input().split() for i in list : print(ans[int(i)])
PYTHON3
474_B. Worms
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 with number...
2
8
from __future__ import division, print_function # import threading # threading.stack_size(2**27) # import sys # sys.setrecursionlimit(10**7) from sys import stdin, stdout import bisect #c++ upperbound import math import heapq i_m=9223372036854775807 def modinv(n,p): return pow(n,p-2,p) def cin(): ret...
PYTHON
474_B. Worms
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 with number...
2
8
def binary_search(arr, val, left, right): if left >= right: if val > arr[left]: return left + 1 else: return left mid = (left + right) // 2 if val == arr[mid]: return mid if val < arr[mid]: return binary_search(arr, val, left, mid - 1) return binary_search(arr...
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> int n, m, a[100005], q[100005], d[100005]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); scanf("%d", &m); for (int i = 0; i < m; i++) scanf("%d", &q[i]); d[0] = 1; for (int i = 1; i < n; i++) d[i] += d[i - 1] + a[i - 1]; d[n] = 10000005; for (int ...
CPP
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; void IIT() {} void solve() { int n, m; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { a[i] += a[i - ...
CPP
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> template <typename T> std::ostream& operator<<(std::ostream& str, const std::vector<T>& v) { str << "["; for (auto n : v) str << n << ", "; str << "]"; return str; } using namespace std; int main() { int n; cin >> n; vector<long long> a(n + 1, 0); long long cum = 0; for (int i...
CPP
474_B. Worms
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 with number...
2
8
def searchWorm(search,num): i=0 j=len(search)-1 ans = len(search)-1 while (i<j): mid = (i+j)//2 if search[mid]>=num: j=mid ans = min(mid,ans) else: i=mid+1 return ans n=int(input()) l=list(map(int,input().split())) q=int(input()) qL=list(map(int,input().split())) search=[l[0]] for i in range(1,n): ...
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int h[1000005]; int n = 0; vector<int> v; int main() { scanf("%d", &n); int z = 0; int kari = 0; for (int i = 0; i < n; i++) { scanf("%d", &kari); if (i == 0) { h[1] = 1; h[kari + 1] = 1; z = kari; } else { h[z + kari + 1]++; ...
CPP
474_B. Worms
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 with number...
2
8
n = int(input()) a = [] a.append(0) a += list(map(int, input().strip().split())) for i in range(2, n + 1): a[i] += a[i - 1] m = int(input()) q = list(map(int, input().split())) def search(query, pileNumber): if query >= a[pileNumber - 1] + 1 and query <= a[pileNumber]: return 1 elif que...
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int c[1001000]; int main() { int a[100010], a2[100010]; int b[100100], b2[100100], n, m; while (cin >> n) { int i; for (i = 0; i < n; i++) { cin >> a[i]; if (i == 0) a2[i] = a[i]; else a2[i] = a[i] + a2[i - 1]; } cin >...
CPP
474_B. Worms
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 with number...
2
8
n = int(input()) w = list(map(int,input().split())) l = [] m=int(input()) j = list(map(int,input().split())) #c=w[0] #l.append(list(range(1,c+1))) r=[] for k in range(1,n+1): #c+=w[k] #l+=(list(range(c+1,c+w[k]+1))) #c += w[k] l+=[k]*w[k-1] for i in j: print(l[i-1]) '''for i in j: first = 0 ...
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> int find_pile(int st, int end, std::vector<int> &piles, int worm) { if (st == end) { return st; } int mid = (st + end) / 2; if (piles[mid] == worm) { return mid; } else if (piles[mid] > worm) { return find_pile(st, mid, piles, worm); } else { return find_pile(mid + 1...
CPP
474_B. Worms
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 with number...
2
8
import bisect n=int(input()) l=list(map(int,raw_input().split())) m=int(input()) q=list(map(int,raw_input().split())) a=[0] for i in xrange(len(l)): a.append(l[i]+a[-1]) for i in xrange(len(q)): print bisect.bisect_left(a,q[i])
PYTHON
474_B. Worms
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 with number...
2
8
import java.io.*; import java.util.*; public class Worms { public static void main (String[] args){ MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int numPiles = sc.nextInt(); Integer [] lista2 = new Integer[numPiles+1]; int ...
JAVA
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int binarySearch(int arr[], int l, int r, int val) { while (l != r) { int mid = (l + r) / 2; if (arr[mid] == val) { return mid; } else if (arr[mid] < val) { l = mid + 1; } else { r = mid; } } return l; } int main() { int n, m, q...
CPP
474_B. Worms
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 with number...
2
8
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; /** * User: anatoly * Date: 25.06.13 * Time: 0:04 */ public class P474B { private static final BufferedInputStream is = new BufferedInputStream(System.in); ...
JAVA
474_B. Worms
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 with number...
2
8
import bisect from itertools import accumulate t=int(input ()) p=list(map(int, input ().split())) m=int(input ()) a=list(map(int, input ().split ())) b=list(accumulate(p)) for j in range (len(a)): print (bisect.bisect_left(b,a[j])+1)
PYTHON3
474_B. Worms
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 with number...
2
8
n=int(input()) a=list(map(int,input().split())) sum=0 d={} c=0 k=0 for i in a: c+=1 for j in range(i): k+=1 d[k]=c input() c=list(map(int,input().split())) for i in c: print(d[i])
PYTHON3
474_B. Worms
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 with number...
2
8
l=[] n=int(input()) r=1 a=list(map(int,input().split())) for k in a: l+=[r]*k r+=1 q=int(input()) qr=list(map(int,input().split())) for q in qr: print(l[q-1])
PYTHON3
474_B. Worms
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 with number...
2
8
L=[] input() p=1 for i in input().split(): L+=[p]*int(i) p+=1 input() for i in input().split(): print(L[int(i)-1])
PYTHON3
474_B. Worms
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 with number...
2
8
from sys import stdin,stdout import bisect def st(): return list(stdin.readline()) def inp(): return int(stdin.readline()) def li(): return list(map(int,stdin.readline().split())) def mp(): return map(int,stdin.readline().split()) n=inp() l=li() m=inp() k=li() x=[] c=0 for i in l: x.append(c+i...
PYTHON3
474_B. Worms
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 with number...
2
8
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class P474B { //static long m=1000000007; static BigInteger ways(int N, int K) { BigInteger ret = BigInteger.ONE; for(int i=N;i>=N-K+1;i--) { ret = ret.multiply(...
JAVA
474_B. Worms
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 with number...
2
8
def binser(lis,val): hi=len(lis)-1 lo=0 while hi!=lo: ind=(hi+lo)/2 if lis[ind]>=val: hi=ind else: lo=ind+1 return hi n=input() a=map(int,raw_input().split()) s=[0] for i in a: s.append(s[-1]+i) m=input() q=map(int,raw_input().split()) for j in q: ...
PYTHON
474_B. Worms
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 with number...
2
8
__author__ = 'Juan Barros' ''' http://codeforces.com/problemset/problem/474/B ''' '''inputCopy 5 2 7 3 4 9 3 1 25 11 ''' def solve(n, a): result = [] sum = [] sumAux = 0 for i in n: sumAux += i sum.append(sumAux) size = len(n) for e in a: result.append(binarySearch(sum...
PYTHON3
474_B. Worms
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 with number...
2
8
num_piles = int(input()) worm_piles = list(map(int, input().split())) num_juicy_worms = int(input()) juicy_worm_labels = list(map(int, input().split())) bins = [] # ith num is min for the bin running_sum = 1 for i in range(1, num_piles + 1): if i == 1: bins.append(running_sum) running_sum += worm_...
PYTHON3
474_B. Worms
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 with number...
2
8
n = int(input()) a = input().split(' ') m = int(input()) b = input().split(' ') k = 1 c = {} for i in range(n): c[i+1] = (k, k+int(a[i])-1) #print(k, k+int(a[i])-1) k = k+int(a[i]) d = [] for j in range(m): r = 1 l = n while (r <= l): mid = l + (r-l)//2 #print('mid ', mid, 'r '...
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int n, a[100100], b[100100], m, res[100100], c[100100], k = 0; pair<int, int> para[100100]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; c[0] = a[0]; for (int i = 1; i < n; i++) c[i] = a[i] + c[i - 1]; cin >> m; for (int i = 0; i < m; i++) { ...
CPP
474_B. Worms
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 with number...
2
8
from bisect import bisect_left n=int(input()) S=A=list(map(int,input().split())) for i in range(1,n): S[i] += S[i-1] m=int(input()) for q in list(map(int,input().split())): print(bisect_left(S, q)+1)
PYTHON3
474_B. Worms
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 with number...
2
8
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque, Counter as c from itertools import co...
PYTHON3
474_B. Worms
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 with number...
2
8
def main(): n = int(raw_input()) an = [int(x) for x in raw_input().split(' ')] m = int(raw_input()) mn = [int(x) for x in raw_input().split(' ')] l = [] for i, x in enumerate(an): for j in range(x): l.append(i+1) for i in range(m): print l[mn[i] - 1] if True: ...
PYTHON
474_B. Worms
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 with number...
2
8
from bisect import bisect_left def find(a, x): i = bisect_left(a, x) return i raise ValueError n = int(input()) d = input().split() d = [int(i) for i in d] m = int(input()) l = input().split() l = [int(i) for i in l] for i in range(1,n) : d[i] += d[i-1] d = [0]+d for j in l : i = find(d,j) prin...
PYTHON3
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1e2; int l[N], n, m, x; int main() { scanf("%d%d", &n, &l[0]); for (int i = 1; i < n; ++i) { scanf("%d", &x); l[i] = l[i - 1] + x; } scanf("%d", &m); for (int i = 0; i < m; ++i) { scanf("%d", &x); printf("%d\n", lower_bound(l, l...
CPP
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int> > piles; int temp; cin >> temp; piles.push_back({1, temp}); for (int i = 1; i < n; i++) { cin >> temp; int last = piles.back().second; piles.push_back({last + 1, last + temp}); } int juicy; ...
CPP
474_B. Worms
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 with number...
2
8
""" arr = list(map(int, input().split())) n,k=map(int, input().split()) """ def binarySearch (arr, l, r, x): # Check base case if r >= l: mid = l + (r - l)//2 # If element is present at the middle itself if arr[mid][0] <=x and arr[mid][1] >= x: return mid ...
PYTHON3
474_B. Worms
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 with number...
2
8
# coding: utf-8 def binsearch(lista, num, lenl): imin, imax = 0, lenl while imin <= imax: imid = (imin+imax)/2 if (num == lista[imid]): return imid+1 else: if (lista[imid] < num): imin = imid+1 else: imax = imid-1 r...
PYTHON
474_B. Worms
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 with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int size; scanf("%d", &size); int arr[size]; for (int i = 0; i < size; i++) scanf("%d", &arr[i]); int arrs[size]; arrs[0] = arr[0]; for (int i = 1; i <= size; i++) { arrs[i] = arrs[i - 1] + arr[i]; } int num; scanf("%d", &num); while (...
CPP