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
#include <bits/stdc++.h> using namespace std; vector<long long> v; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); long long n, x, r = 0, m; cin >> n; for (long long i = 0; i < n; i++) { cin >> x; r += x; v.push_back(r); } cin >> m; for (long long 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
#include <bits/stdc++.h> using namespace std; int arr[1000000 + 10]; int a[1000000 + 10]; int main() { int t, i, j, b, c, n, m, k; scanf("%d", &n); k = 1; c = 0; for (i = 0; i < n; ++i) { scanf("%d", &a[i]); if (i > 0) a[i] += a[i - 1]; } j = 1; for (i = 0; i < n; ++i) for (; j <= a[i]; ++j)...
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.util.Scanner; public class B_Worms { public static void main(String[] args) { Scanner in = new Scanner(System.in); int heapN = in.nextInt(); int[] heaps = new int[heapN + 1]; heaps[0] = 0; for (int i = 1; i <= heapN; i++) { heaps[i] = heaps[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.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.lang.Integer; impo...
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.Arrays; import java.util.Scanner; public class worms { public static int binarySearch( int[] a , int x) { int m ; int l = 0; int r =a.length -1; int maxSmallerI = 0; while( l <= r ) { m = (l+r)/2; if( a[m] < x ) { if( a[m] > a[maxSmallerI] ) maxSmallerI = m; l = m+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.Scanner; public class afew { public static void main(String args[]) { int sum = 0; Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); sum += arr[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
from collections import deque def Bsearch(arr , x): l ,r = 0 , len(arr) - 1 while l <= r : mid = l + (r - l ) // 2 if arr[mid] < x : l = mid + 1 elif arr[mid] > x : r = mid - 1 else: return mid + 1 if arr[l] > x : return l +...
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
import java.io.*; import java.util.*; public class Worms { public static void main(String[] args) { FastReader fastreader = new FastReader(); int n = fastreader.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = fastreader.nextInt(); } ...
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 __future__ import division, print_function DEBUG = 0 import os, sys from atexit import register from io import BytesIO import itertools if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip if DEBUG: debug_prin...
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 ara[100010]; vector<long long> v; vector<long long> v1; long long val, sum, val1; int main() { long long n, m; sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> val; v.push_back(val); } for (int i = 0; i < n; i++) { sum += v.at(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> using namespace std; int n, a[1000005], i, k, m; int main() { cin >> n; a[0] = 1; for (i = 0; i < n; i++) { cin >> m; k += m; a[k + 1]++; } for (i = 1; i < 1000003; i++) a[i] += a[i - 1]; cin >> m; for (i = 0; i < m; i++) { cin >> k; cout << a[k] << 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
import java.util.*; public class test13 { public static void main(String[] args) { Scanner in = new Scanner(System.in); StringBuilder out = new StringBuilder(); int n = in.nextInt(); int[] p = new int[n+1]; for (int i = 1; i <= n; i++) { p[i] = p[i-1] + in.nextInt...
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 bisect import bisect_left def binarySearch(array,x): temp = bisect_left(array,x) try: if array[temp] == x: return temp+1 else: return temp except: return temp n = (input()) listi = list(map(int,input().split())) sumv = 0 array = [] for i in listi: 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
a = int(input()) b = [int(x) for x in input().split()] c = int(input()) d = [int(x) for x in input().split()] structure = [0] count = 1 for x in b: for y in range(x): structure.append(count) count += 1 for x in d: print(structure[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
n=int(input()) a=[int(i) for i in input().split()] m=int(input()) q=[int(i) for i in input().split()] q=[[q[i],i] for i in range(m)] q.sort() x=0 h=[0]*m j=0 for i in range(n): if j==m: break x+=a[i] if x>=q[j][0]: kk=True while(kk): h[q[j][1]]=i+1 j+=1 if j==m: kk=False ...
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 w[100002]; int main() { int i, j, n, m, q, first, last, mid; while (scanf("%d", &n) == 1) { for (i = 1; i <= n; i++) { scanf("%d", &j); w[i] = w[i - 1] + j; } scanf("%d", &m); for (i = 1; i <= m; i++) { scanf("%d", &q); first = 1; last = n; ...
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 sys def binarySearch(arr, val): l = 0 r = len(arr) while(l < r - 1): m = int((l + r) / 2) if(arr[m] < val): l = m else: r = m return r n = int(sys.stdin.readline()) z = [int(x) for x in (sys.stdin.readline()).split()] an = [0] for i in...
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
/* * DA-IICT * Author: Jugal Kalal */ import java.util.*; import java.io.*; import java.math.*; import java.text.DecimalFormat; public class Hackerrank{ static long mod=(long)Math.pow(10,9)+7; public static void main(String args[]) { new Thread(null, new Runnable() { public void run() { ...
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 bs(k): global n l = 0 r = n+1 while l <= r: mid = (l+r) // 2 if k >= pref[mid] + 1 and k <= pref[mid+1]: return mid if k <= pref[mid]: r = mid else: l = mid + 1 n = int(input()) arr = list(map(int,input().split())) pref = ...
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::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> v; v.push_back(0); int cur = 0; for (int i = 1, x; i <= n; i++) { cin >> x; x += cur; v.push_back(x); cur = v[i]; } int m; cin >> m; for (int i = 0, a;...
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
kheap=int(input()) heaps=list(map(int,input().split())) kworms=int(input()) worms=list(map(int,input().split())) d1={i:0 for i in range(1,sum(heaps)+1)} prev=0 counter=1 for i in heaps: start=prev+1 prev+=i for i2 in range(start,prev+1): d1[i2]=counter counter+=1 for num in worms: print(d1[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
n = int(input()) l = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) for i in range(1,n): l[i]+=l[i-1] s = l[-1] j = 0 p = [0] for i in range(1,s+1): if i>l[j]: j+=1 p.append(j+1) for i in range(m): print(p[q[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
n = int(input()) a = [int(x) for x in input().split()] q = int(input()) queries = [int(x) for x in input().split()] ans = list() for i in range(n): for k in range(a[i]): ans.append(i) for x in queries: bla=int(x) print(ans[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
import bisect n=int(input()) L=[int(i) for i in input().split()] for i in range(0,n-1): L[i+1]+=L[i] x=int(input()) A=[int(i) for i in input().split()] for i in A: print(bisect.bisect_left(L,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
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: print...
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 cf271_2_2 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int sum=0; int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); } int m=sc.nextInt(); int b[] = new int[m]; for(int i=0;i<m;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
from bisect import bisect_left from sys import stdin, stdout n = int(stdin.readline()) a = list(map(int, stdin.readline().split(' '))) for i in range(1, len(a)): a[i] += a[i-1] m = int(stdin.readline()) qs = list(map(int, stdin.readline().split(' '))) for q in qs: stdout.write(str(bisect_left(a, q)+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
n = int(raw_input()) a = map(int, raw_input().split()) m = int(raw_input()) for i in xrange(1, n): a[i] = a[i - 1] + a[i] from bisect import bisect_left def query(x): return str(bisect_left(a, x) + 1) ans = map(query, map(int, raw_input().split())) print "\n".join(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
#https://codeforces.com/problemset/problem/474/B n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) b = [a[0]] for i in range(1, len(a)): b.append(a[i] + b[-1]) for i in range(m): l = -1 r = len(b) while l+1 < r: mid = (l+r)//2 if ...
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 import bisect def main(): n=int(input()) f=0 k=[] for j in list(map(int,input().split())): k.append(j+f) f=j+f m=int(input()) for j in list(map(int,input().split())): print(bisect.bisect_left(k, j)+1) if __name__=='__main__': 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
l=[] input() c=1 for k in input().split(): l+=[c]*int(k) c+=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()) li = list(map(int, input().split())) y = int(input()) li1 = list(map(int, input().split())) li2 = [] for i in range(x): li2 += [i+1]*li[i] for i in li1 : print(li2[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
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
import bisect n = int(raw_input()) a = map(int,raw_input().split()) lis = [] lis.append(a[0]) for i in range(1,n): lis.append(a[i]+lis[-1]) m = int(raw_input()) b = map(int,raw_input().split()) for i in xrange(m): val = bisect.bisect(lis, b[i]) if lis[val-1] == b[i]: print val else: print val+1
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
n = input() ; l = [int(i) for i in input().split()] x = input() ; x = [int(i) for i in input().split()] master = [] j = 1 ans = [] for i in l: master += [j]*i; j+=1 for i in x: ans.append(master[i-1]) print(*ans)
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
nlabel = int(raw_input()) nworm = (raw_input()).split(" ") njuicy = int(raw_input()) nplace = (raw_input()).split(" ") worm = [] for i in range(nlabel): worm.extend([i+1] * int(nworm[i])) for i in range(njuicy): print worm[int(nplace[i])-1] # nlabel = int(raw_input()) # worm = (raw_input()).split(" ") # njui...
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; template <typename T> using vt = vector<T>; const int N = 1e5 + 5; int n, a[N]; int binary_search(int q) { int lo = 1, hi = n; while (lo < hi) { int mid = (lo + hi) / 2; if (a[mid] < q) lo = mid + 1; else if (a[mid] > q) hi = mid; else ...
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=input() a=map(int,raw_input().split()) b=[0]*10000005 x=1 for i in range(0,n): y=a[i]+x for j in range(x,y): b[j]=i+1 x=y q=input() a=map(int,raw_input().split()) for i in range(0,q): print b[a[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
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:367721060") using namespace std; int a[1010000]; int ans[1010000]; int main() { std::ios::sync_with_stdio(0); int n, m, query; long long sum = 0; int cnt = 1; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } int tmp = a...
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 bin_search(b, q): l = 0 r = len(b)-1 while r - l > 1: k = (l+r)/2 if q > b[k]: l = k else: r = k #k = (l+r)/2 #print b #print "b[" + str(r) + "] = " + str(b[r]) if b[r] > q: return l else: return r n = int(raw_input("")) a = ra...
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 n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) x = [ 0 for i in range(len(a))] x[0] = a[0] for i in range(1,len(a)): x[i] = 0 + x[i - 1] + a[i] #print(x) for i in b: print(bisect_left(x, 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 ceilSearch(int arr[], int low, int high, int x) { int mid; if (x <= arr[low]) return low; if (x > arr[high]) return -1; mid = (low + high) / 2; if (arr[mid] == x) return mid; else if (arr[mid] < x) { if (mid + 1 <= high && x <= arr[mid + 1]) re...
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 i 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
from time import time n = int(input()) a = list(map(int,input().split(' '))) m = int(input()) q = list(map(int,input().split(' '))) def search(l,n,s,e): #print(l,n,s,e) if s == e: return s if s + 1 == e: if n > l[s] : return e else : return s mid = (s+e...
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()) l1=[int(i) for i in input().split()] y=int(input()) check=[int(i) for i in input().split()] for i in range(1,x): l1[i]+=l1[i-1] mid=0 index=0 flag=1 for i in range(y): l=0 h=x-1 index=0 while l<=h: mid=(l+h)//2 if l1[0]>=check[i]: index=0 fl...
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()) w=list(map(int, input().split())) input() q=list(map(int, input().split())) b=[] for i in range(n): b += [i+1]*w[i] for i in q: 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
from bisect import bisect_left n=int(input()) a=[int(i) for i in input().split()] m=int(input()) q=[int(i) for i in input().split()] sumlist=[a[0]] i=1 while i<n: k=sumlist[i-1]+a[i] sumlist.append(k) i+=1 for i in q: y = bisect_left(sumlist, i) if y!= n: print(y+1) else: print(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
def binSearch(l, r, k): mid = (l+r)/2 if (l < r): if (k == cum[mid]): return mid elif (k < cum[mid]): return binSearch(l, mid - 1, k) else: return binSearch(mid + 1, r, k) else: # check which one to return # print l, r return r+1 if cum[r] < k else r n = input() a = map(int, raw_input().split())...
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
n = input() kuchki = map (int, raw_input().strip().split()) s = input() sochni = map (int, raw_input().strip().split()) summi = [] for i in xrange(n): summi += [i+1]*kuchki[i] for x in sochni: print summi[x-1]
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
p = input() x = list(map(int, input().split())) o = input() y = list(map(int, input().split())) worms = {} cur_worm = 1 for knot_number, length in enumerate(x): for _ in range(length): worms[cur_worm] = knot_number + 1 cur_worm += 1 for worm_number in y: print(worms[worm_number])
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())) input() q = list(map(int,input().split())) k = [] for i in range(n): k += [i] * a[i] for i in q: print(k[i - 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
# coding=utf-8 if __name__ == '__main__': n = int(input()) line = str(input()).split() line = [int(it) for it in line] value = list() for i in range(n): value.extend([i] * line[i]) m = int(input()) line = str(input()).split() line = [int(it) for it in line] for i in range(m)...
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(raw_input()) a = map(int, raw_input().split()) m = int(raw_input()) q= map(int, raw_input().split()) precompute=dict() index=1 cumulatea=[i for i in a] for i in xrange(1,len(cumulatea)): cumulatea[i]+=cumulatea[i-1] for i in xrange(1,cumulatea[-1]+1): precompute[i]=index if i==cumulatea[index-1]: ...
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.*; import java.io.*; import java.math.*; public class cf { static int n; static int arr[]; static int cum[]; static int m; static PrintWriter out; public static void binsearch(int x,int beg,int end) { while(beg<end) { int mid=(beg+end)/2; ...
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 import math import bisect def main(): n = int(input()) A = list(map(int, input().split())) for i in range(1, n): A[i] += A[i-1] q = int(input()) B = list(map(int, input().split())) for b in B: p = bisect.bisect_left(A, b) print(p + 1) if __name__ == "__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
#include <bits/stdc++.h> using namespace std; int pile_num, pile[100001], label_num, label[100001]; int prefix[100001]; int main() { while (scanf("%d", &pile_num) == 1) { for (int i = 0; i < pile_num; i++) scanf("%d", &pile[i]); scanf("%d", &label_num); memset(prefix, 0, sizeof(prefix)); prefix[0] = p...
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
# -*- coding: utf-8 -*- # @Date : 2018-09-29 20:30:50 # @Author : raj lath (oorja.halt@gmail.com) # @Link : link # @Version : 1.0.0 from sys import stdin max_val=int(10e12) min_val=int(-10e12) def read_int() : return int(stdin.readline()) def read_ints() : return [int(x) for x in stdin.readline().spli...
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() { long long n; cin >> n; long long Ar[100005] = {0}; for (int i = 1; i <= n; i++) cin >> Ar[i]; for (int i = 2; i <= n; i++) { Ar[i] += Ar[i - 1]; } long long q; cin >> q; long long ans = INT_MAX; while (q--) { long long x; 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
#include <bits/stdc++.h> using namespace std; long long A[100001], n; long long search1(long long p) { long long lo = 0, hi = n - 1, mid; while (lo <= hi) { mid = (lo + hi) / 2; if (mid == 0) { if (A[0] >= p) { return 1; } if (A[0] < p) { lo = mid + 1; } } else if...
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 calculate_partial_sums(num_worms, num_piles): partial_sums = [0] * num_piles partial_sums[0] = num_worms[0] for i in range(1, num_piles): partial_sums[i] = partial_sums[i-1] + num_worms[i] return partial_sums def binary_search(partial_sums, target): low = 0 high = len(partial_sums)...
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> int a[1000001], n, x, k = 1, i, j, m; using namespace std; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> x; for (j = k; j < x + k; j++) a[j] = i; k = k + x; } cin >> m; while (m--) { cin >> x; cout << a[x] << "\n"; } }
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 binarySearch(list, value, length): l = 0 r = length-1 while (l <= r): mid = (l + r) // 2 #print(list[mid]) if(list[mid-1] == list[length-1] and list[mid] >= value): return mid elif (list[mid-1] < value and list[mid] >= value): return mid el...
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.*; public class CF { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args) throws IOException { br.readLine(); ...
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
input() pos = [] aux = 1 for e in input().split(): pos+=[aux]*int(e) aux+=1 input() for e in input().split(): print(str(pos[int(e)-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()) l=list(map(int,input().split())) n1=int(input()) l1=list(map(int,input().split())) s=0 S=[] for i in range(n) : s=s+l[i] S.append(s) for x in l1 : print(bisect_left(S,x)+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 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
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class C474B { public static class Heap { public int begin = 0; public int end = 0; public Heap(int begin, int end) { this.begin = begin; this.end = end; } } protected static int rank(int key, Heap[] h...
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 bisect import bisect input() a=list(map(int,input().split())) input() b=list(map(int,input().split())) a1=[1]; ans="" for item in a: a1.append(a1[-1]+item) for item in b: ans+=f"{bisect(a1,item)}\n" print(ans)
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
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author zhanaratlebaldy */ public class Main { /** * @param args the command line argu...
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; long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; long long ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } long long lcm(long long a, long lo...
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
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n=int(input()) p=[int(x) for x in input().split()] m=int(input()) j=[int(x) for x in input().split()] w=[0]*(10**6+1) s=1 for i in range(n): w[s:s+p[i]]=[i+1]*p[i] s+=p[i] for i in j: print(w[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
n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) t=[] for k in range(n): for j in range(a[k]): t.append(k+1) for i in range(m): print(t[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
######### ## ## ## #### ##### ## # ## # ## # # # # # # # # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # ##### # # # # ### # # # # # # # # ##### # # # # # # # # # # # # # # # # # # ########...
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 search(int a[], int x, int n) { int lo = 0; int hi = n; while (lo <= hi) { int mid = (lo + hi) / 2; if (a[mid] >= x && a[mid - 1] < x) return mid; else if (a[mid] > x) hi = mid - 1; else lo = mid + 1; } return 0; } int main() ...
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()) line = input().split() worms = [0] for i in range(n): worms += [i + 1] * int(line[i]) input() line = input().split() for i in line: print(worms[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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; import java.util.List; public class test { public static void main(String[] args) throws IOException { // TO...
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 count(int* a, int i, int j, int b) { if ((j - i) == 1) { return i; } if ((j - i) == 2) { int c; if (b <= a[i]) c = i; else c = i + 1; return c; } int m = (i + j) / 2; if (b > a[m - 1]) return count(a, m, j, b); else ...
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 *A; int bin_s(int val, int left, int right) { int m = (left + right) / 2; if (A[m] >= val) { if (A[m - 1] < val) return m; else return bin_s(val, left, m - 1); } else return bin_s(val, m + 1, right); } int main() { int n, q, x; cin >> n...
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 = [int(x) for x in input().split()] a=[l[0]] for i in range(1,n): a+=[a[i-1]+l[i]] #print(a) q = int(input()) m=[int(x) for x in input().split()] for i in range(len(m)): if(m[i]<=a[0]): print(1) continue res=bisect.bisect_left(a,m[i]) print(res+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
input() W = [] for i, v in enumerate(list(map(int, input().split() ) ) ): W += [i+1] * v input() for v in list(map(int, input().split() ) ): print(W[v-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.io.*; import java.util.*; public class Worms { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() ...
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
numberOfpies = int(raw_input()) wormsInpiles = raw_input().split() numbersOfMarmotChoices = int(raw_input()) elements = raw_input().split() lista = [] x = 1 for i in range(numberOfpies): for j in range(int(wormsInpiles[i])): lista.append(i+1) for i in range(len(elements)): # print int(elements[i]) print lista[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
#http://codeforces.com/problemset/problem/474/B def bin_search(target, arr, n): s = 0; e = n-1 while e-s>1: m = (s+e)/2 if target < arr[m]: e = m else: s = m if target > arr[s]: return e+1 return s+1 def main(): n = int(raw_input("")) arr_input = map(int, raw_input().split(" ")) edge_list = [0...
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
n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) z=[] for i in range(n): for j in range(a[i]): z.append(i+1) for k in b: print(z[k-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 search(arr,label): low=0 high=len(arr) while low!=high: mid=(high+low)//2 if arr[mid]<label: low=mid+1 else: high=mid return low+1 n=int(input()) arr=list(map(int,input().split())) new=[] prev=0 for num in arr: new+=[prev+num] prev=prev+num m=...
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()) B = list(map(int, input().split())) C = [0] for i in range(n): C.append(C[i] + A[i]) for j in range(len(B)): l = 0 r = len(C) while r - l > 1: mid = (l + r) // 2 if C[mid] >= B[j]: r = mid elif C[m...
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
# Enter your code here. Read input from STDIN. Print output to STDOUT n = int(raw_input()) a = map(int,raw_input().split()) b = [0 for _ in xrange(n)] b[0] = a[0] for i in range(1,n): b[i] = b[i-1]+a[i] m = int(raw_input()) import bisect q = map(int,raw_input().split()) for i in range(m): t = q[i] print bis...
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 get_ints(): return map(int, raw_input().split(' ')) n = int(raw_input()) a = get_ints() ans = [0] * sum(a) last_pos = 0 for i in xrange(n): for j in xrange(a[i]): ans[last_pos] = i last_pos += 1 m = int(raw_input()) q = get_ints() for cq in q: print ans[cq - 1] + 1
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
entrada = int(input()) gusanos = list(map(int,input().strip().split(" "))) jugosos = int(input()) gusanos_jugosos = list(map(int,input().strip().split(" "))) def Busqueda_binaria(x,l,g): lista = [0]*x cont = 0 for i,j in enumerate(l): cont = lista[i]= j + cont for k in g: izq = 0 der = x-1 while izq < der:...
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 Main{ static char arr[][]; public static void main(String[] args) throws IOException { Scanner in=new Scanner(System.in); int n=in.nextInt(); int arr[]=new int[1000000]; int k=0; int temp=0; int i,j; for(i=0;i<n;i++){ temp=temp+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
N = int(input()) worms = list(map(int, input().split())) Q = int(input()) querys = list(map(int, input().split())) worm_no = [0] for no, num in enumerate(worms): worm_no.extend([no+1 for i in range(num)]) for q in querys: print(worm_no[q])
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.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Scanner; public class Worms { public static void main(String[] args) { // TODO Auto-generated method stub InputStream in = System.in; OutputStream out = System.out; Scanner t = new Scanner(in); PrintWrit...
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()) aa = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) a = [0] for i in range(n): for j in range(aa[i]): a.append(i+1) for qq in q: print(a[qq])
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; cin >> n; int a[100010]; int sum = 0; for (int i = 0; i < n; i++) { int temp; cin >> temp; sum += temp; a[i + 1] = sum; } int m; cin >> m; for (int i = 0; i < m; i++) { int temp; cin >> temp; cout << lower_bo...
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.FileNotFoundException; import java.util.Scanner; public class B { public static void main(String zargs[]) throws FileNotFoundException { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int x[] = new int[n]; x[0] = scanner.nextInt(); for...
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 main() { int n; scanf("%d", &n); vector<int> vec(n); for (int i = 0; i < n; i++) scanf("%d", &vec[i]); vector<int> cs(n); cs[0] = vec[0]; for (int i = 1; i < n; i++) cs[i] = cs[i - 1] + vec[i]; int t; scanf("%d", &t); int find; for (int i = 0; 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
import bisect t=int(input ()) p=list(map(int, input ().split())) m=int(input ()) a=list(map(int, input ().split ())) b=[0] s=0 for i in range (len(p)): s=s+p[i] b.append(s) for j in range (len(a)): print (bisect.bisect_left(b,a[j]))
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
# Codeforces contest 271d1 problem B import bisect n = int(input()) worms = [int(x) for x in input().split(' ')] for i in range(n-1): worms[i+1] += worms[i] m = int(input()) v = [int(x) for x in input().split(' ')] [(lambda x: print(bisect.bisect_left(worms, x)+1))(x) for x in v]
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 ques478B{ public void run() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); int [] arr = new int[n]; String [] strArr = br.read...
JAVA