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 bisect x=int(input()) a=list(map(int,input().split())) b=[] s=0 y=int(input()) c=list(map(int,input().split())) for i in range(len(a)): s=s+a[i] b.append(s) for j in range(len(c)): z=bisect.bisect_right(b,c[j],0,len(b)-1) if(c[j]==0): print(0) elif(b[z-1]==c[j]): print(z) ...
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())) l=[] l.append(a[0]) for i in range(1,n): l.append(l[i-1]+a[i]) #print(l) s=0 ans=0 r=n-1 for i in b: s=0 ans=0 r=n-1 while s <= r: mid = (s+r) // 2 if 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
from collections import deque, Counter, OrderedDict from heapq import nsmallest, nlargest from math import ceil,floor,log,log2,sqrt,gcd,factorial def binNumber(n,size=1): return bin(n)[2:].zfill(size) def iar(): return list(map(int,input().split())) def ini(): return int(input()) def isp(): return ma...
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() { pair<long long int, long long int> vr[100001]; int n, sum = 1; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; int temp1, temp2; temp1 = sum; temp2 = (a[i] + sum) - 1; sum += a[i]; vr[i].first = temp1; vr[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 bs(lista, numero): izq = 0 der = len(lista) - 1 while izq != der: med = (izq + der) // 2 if lista[med] >= numero: der = med else: izq = med + 1 return izq n = int(input()) lista = [] for i in input().split(" "): lista.append(int(i)) lista_sumas =...
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()) worms = list(map(int, input().split())) m = int(input()) juicy = list(map(int, input().split())) s = [] for i in range(n): s += [i]*worms[i] for i in range(m): print(s[juicy[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
import java.util.*; public class Worms{ public static void main(String []args){ java.util.Scanner scan=new java.util.Scanner(System.in); int n=scan.nextInt(); int []arr=new int[n]; for(int i=1;i<=arr.length;i++){ arr[i-1]=scan.nextInt(); } int q=scan.nextInt(); int []queries=new int[q]; for(int 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
n=int(input()) now=list(map(int,input().split())) input() fi=list(map(int,input().split())) """k=fi.copy() k.sort() di={} li=[] init=1 k1=0 no=1 for i in range(len(now)): if k1>=len(k): break if k[k1] in list(range(init,now[i]+init)): di[k[k1]]=no k1+=1 init+=now[i] no+=1 for i 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()) l=[int(i) for i in input().split()] l1=[] k1=1 for i in range(n): l1+=[k1]*l[i] k1+=1 m=int(input()) q=[int(i) for i in input().split()] for i in range(m): print(l1[q[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
k=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) c=0 d=[] for i in range(1,len(a)+1): for j in range(a[i-1]): d.append(i) for i in b: print(d[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
input() l=[] r=1 for i in input().split(): l+=[r]*int(i) 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
import java.awt.image.AreaAveragingScaleFilter; import java.util.*; public class Q3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long sum[] = new long[n+1]; sum[0] = 0; for (int i = 1; i <= n; i++) { sum[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
n=int(input()) l=list(map(int,input().split())) k=[0] for i in range(n): k+=[k[-1]+l[i]] m=int(input()) l=list(map(int,input().split())) ans=[] for x in l: l,r,a=0,n,n while l<=r: m=(l+r)//2 if x<=k[m]: a=m; r=m-1 else: l=m+1 ans+=[str(a)] print('\n'.join(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
import sys input = sys.stdin.readline from itertools import accumulate as acc from bisect import bisect_left as bl n = int(input()) x = [0] + [*acc(map(int, input().split()))] m = int(input()) y = [*map(int, input().split())] z = [bl(x, i)for i in y] print(*z, sep = '\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
#! -*- coding:utf-8 -*- def main(): n = int(raw_input()) a = map(int, raw_input().split()) for i in xrange(1, n): a[i] += a[i - 1] tmp = int(raw_input()) q = map(int, raw_input().split()) for qi in q: lef = -1 rig = n - 1 while lef + 1 < rig: mid = (...
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()) l = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) a = [] s = sum(l) prev = l[0] count = 1 for i in range(s): if i<prev: a.append(count) else: count+=1 prev += l[count-1] a.append(count) for i in m: print(a[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 java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Iterator; import java.util.StringTokenizer; import javax.swing.text.Highlighter; public class Main { public static int arr[]; public static void main(String[] args) { Scanner scn = new Scanner(); while (scn.has...
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 * n = int(input()) l = list(map(int , input().split(' '))) a = [l[0]] m = int(input()) for i in range(1 , n): a.append(a[i - 1] + l[i]) o = list(map(int , input().split(' '))) for i in o: print(bisect_left(a , i , 0 , n) + 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
#!/usr/bin/env python # 00:36 start import bisect n = int(input()) a = list(map(int, input().split())) b = [0] * (len(a) + 1) for i in range(len(a)): b[i+1] = b[i] + a[i] nq = int(input()) qs = map(int, input().split()) for q in qs: print(bisect.bisect_left(b, 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
n= int(input()) l= list(map(int,input().split())) t= int(input()) m = list(map(int,input().split())) worm=[l[0]] for i in range(1,len(l)): worm.append(l[i]+worm[i-1]) def binarySearch(worm, l, r): while l <= r: mid = l + (r - l) // 2 if worm[mid] == m[j]: return mid+1 elif ...
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()] b = [] cnt = 1 for i in range(n): for j in range(a[i]): b.append(cnt) cnt += 1 m = int(input()) q = [int(i) for i in input().split()] 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 * n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) a = [0] + a for i in range(1, len(a)): a[i] += a[i - 1] for x in q: print(bisect_left(a, x, 0, len(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()) lst_n = list(map(int,input().split())) m = int(input()) lst_m = list(map(int,input().split())) L = [] r = 1 for k in lst_n: L += [r] * int(k) r += 1 for j in lst_m: 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
n = int(raw_input()) piles = map(int, raw_input().split(' ')) ans = [-1] for index, pile in enumerate(piles): for i in range(pile): ans.append(index+1) num_queries = int(raw_input()) queries = map(int, raw_input().split(' ')) for query in queries: print ans[query]
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 Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); // int numPiles = Integer.parseInt(in.nextLine()); int numPiles = in.nextInt(); int[] piles = new int[numPiles]; for(int i = 0; i < numP...
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, m, a[1111111]; int main() { scanf("%d", &n); a[0] = 0; for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); a[i] = a[i - 1] + x; } scanf("%d", &m); while (m--) { int x; int res = 0; scanf("%d", &x); int lef = 1, rig = 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
from bisect import bisect_left def bs(a, x, lo=0, hi=None): # can't use a to specify default for hi hi = hi if hi is not None else len(a) # hi defaults to len(a) pos = bisect_left(a,x,lo,hi) # find insertion position return (pos if pos != hi and a[pos] >= x else -1) # don't walk off the end ...
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.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { static int[] lower; static int[] upper; static 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 java.io.*; import static java.lang.Math.*; import java.util.Arrays; public class Main { 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
#include <bits/stdc++.h> using namespace std; long long int n, m, i, j, k; long long int sum = 0; long long int b_search(long long int b[], long long int lo, long long int hi, long long int x, long long int pos) { if (lo > hi) { return pos; } long long int mid = lo + (hi - lo) / 2; 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
#include <bits/stdc++.h> using namespace std; long long binary(long long a[], long long l, long long r, long long x) { long long mid, ans = -1; while (r >= l) { mid = (l + r) / 2; if (x <= a[mid]) { ans = mid; r = mid - 1; } else l = mid + 1; } return ans; } signed main() { ios_b...
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.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; /** * Created by hama_du on 2014/10/09. */ public class ProblemB { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = ...
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 { static boolean check(int mid) { int p = 5*(mid)*(mid+1)/2; return p>10; } static int binaryS(int low, int hi){ int res = -1; int mid; while (low <= hi) { mid = low + (hi - low) / 2; if (check(mid)) { ...
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 binary(int st, int en, int s[], int k) { while (en >= st) { int mid = st + (en - st) / 2; if (k < s[0]) { return st; } if (k > s[en]) { return en; } if (k == s[mid]) { return mid; } if (k >= s[mid] && k <= s[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
def bsearch(arr, n): l = 0 r = len(arr) - 1 while l <= r: mid = (l+r) // 2 if arr[mid] >= n and arr[mid-1] < n: return mid + 1 elif arr[mid] < n: l = mid + 1 else: r = mid - 1 if mid == 0: return 1 else: return len(...
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 = [] r = 1 input() for i in input().split(): l += [r]*int(i) 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
n=int(input()) arr=map(int,raw_input().split()) m=int(input()) inp=map(int,raw_input().split()) fin_lis=[] fin_lis.append(arr[0]) for i in range(1,n): fin_lis.append(arr[i]+fin_lis[i-1]) a=[0]*1000010 j=0 maxi=max(fin_lis) for i in range(maxi+1): if i > fin_lis[j]: j+=1 a[i]=j+1 for i in inp: print 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
from itertools import accumulate n = int(input()) a = list(accumulate(int(i) for i in input().split())) indices = [None] j = 0 for i in range(1, a[n - 1] + 1): if i > a[j]: j += 1 indices.append(j + 1) input() for bi in (int(i) for i in input().split()): print(indices[bi])
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
from itertools import accumulate from bisect import bisect_left if __name__ == "__main__": n = int(input()) worms = list(map(int, input().split())) array = [0] + list(accumulate(worms)) input() queries = list(map(int, input().split())) for target in queries: print(bisect_left(array...
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 MAX_N = 101010; int a[MAX_N], sum[MAX_N]; int main() { int n, m, q; while (scanf("%d", &n) == 1) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; scanf("%d", &m); while (m--) { sc...
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
list = [] input() i = 1 for k in input().split(): list += [i]*int(k) i += 1 input() for j in input().split(): print(list[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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class Worms { static long [] [] num ; static int n; public static void main(String[]args) throws IOException{ BufferedReader br = new BufferedReader(new Inpu...
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.IOException; import java.io.PrintWriter; import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Main { static class Reader { private BufferedReader br; private StringTokenizer token; protected Reader(Input...
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() piles = [int(x) for x in input().split()] cumulated_piles = [0] for x in piles: cumulated_piles.append(x+cumulated_piles[-1]) n = int(input()) placeholder_juicy = [0]*n juicy = sorted([(i,int(x)) for i,x in enumerate(input().split())],key = lambda x: x[1]) c = 0 for i,x in enumerate(cumulated_piles): ...
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 b_s { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int n = sc.nextInt(); int[] arr = new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } int[] p ...
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() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, x = 1; cin >> n; long long int a[n]; long long int p[1000001]; for (long long int i = 0; i < n; i++) { cin >> a[i]; while (a[i]--) { p[x] = i + 1; x++; } }...
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 5 2 7 3 4 9 3 1 25 11 ''' from bisect import bisect n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) x = [] s = 0 for i in range(n): s += a[i] x.append(s+1) for j in q: print(bisect(x,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 find_pile(m, l): b = 0 e = len(l)-1 r = -1 while b<=e: mid = b + (e-b)//2 if m <= l[mid]: r = mid e = mid-1 else: b = mid+1 return r n = int(input()) a = list(map(int, input().split())) for i in range(1, n): a[i] += a[i-1] m = int(input()) for x in list(map(int, input().split())): print(1+f...
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
//package codeForcesPractice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class worms { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputSt...
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.InputStreamReader; public class Worms { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] worms = br.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()) temp=input() temp=temp.split(" ") m=int(input()) t1=input() t1=t1.split(' ') a=list(map(int,t1)) b=a.copy() a.sort() dic={} i=0 start=1 search=a[i] sum=0 count=1 for x in temp : sum+=int(x) if start<=search<=sum: while start<=search<=sum: dic[search]=count 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 n, m, a[100001], q, sum; int b[1000001]; int main() { int n, m, q, sum = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i] + sum] = i; b[1 + sum] = i; sum += a[i]; } cin >> m; for (int j = 1; j <= m; j++) { cin >> q; 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 search(l,st,en,val): if st<=en: mid=(st+en)//2 if l[mid]<=val and mid==en: return mid if l[mid]<=val and l[mid+1]>val: return mid if val<l[mid]: return search(l,st,mid-1,val) else: return search(l,mid+1,len(l)-1,val) els...
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 binary_search(int arr[], int n, int a) { int low, high, mid; low = 0; high = n - 1; while (high > low) { if ((low + 1) == high) { if (arr[low] < a) return high; return low; } mid = (low + high) / 2; if (arr[mid] == a) return mid; ...
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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class B { public static int upper_bound(int[] arr, int key) { int lower = 0, upper = arr.length - 1, ans = -1; while (lower <= upper) { int mid = (lower + upper) / 2; if (key...
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 solve(cumsum, N, num): l = -1 h = N # [l, h) while l + 1 < h: mid = (l+h)/2 if cumsum[mid+1] < num: l = mid else: h = mid return h + 1 N = input() arr = map(int, raw_input().split()) input() nums = map(int, raw_input().split()) # arr = [ 2, 7, 3, 4, 9] # nums = [1,25,11] # N = 5 cumsum = [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
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> nums(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> nums[i]; nums[i] += nums[i - 1]; } int m, x; cin >> m; for (int i = 0; i < m; i++) { cin >> x; int index = (int)(lower_bound(nums.begin(), nums....
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 gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long binSrc(long long arr[], long long n, long long item) { long long mid, lo, hi; lo = 0; hi = n - 1; while (lo <= hi) { mid = (lo + hi) / 2; if (arr[mid] == item) ...
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
# # 474B. Worms # def binary_search(a, key): left = 0 right = len(a) - 1 while left <= right: middle = left + (right - left) / 2 if (middle == 0 or a[middle - 1] < key) and a[middle] >= key: return middle elif a[middle] < key: left = middle + 1 el...
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 printArr(arr): # for i in range(len(arr)): # print("{}. {}".format(i, arr[i])) # # # import sys # sys.stdin = open("#input.txt", "r") n = int(input()) ws = list(map(int, input().split())) k = int(input()) jl = list(map(int, input().split())) js = sorted(jl) j = 0 w = 0 wcum = 0 d = dict() while j < k: while ...
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()) v = list(map(int, input().split())) m = int(input()) M = list(map(int, input().split())) for i in range(1, n): v[i] += v[i-1] def tap(x): global v, n h, t = 0, n while (h <= t): mid = (h+t)//2 if (v[mid] >= x): t = mid-1 else: h = mid+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() t=1 for k in input().split(): L+=[t]*int(k) t+=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
def binsearch(a,x): l,r=0,len(a)-1 ans=len(a) while l<=r: mid=l+(r-l)//2 if a[mid]>=x: ans=mid+1 r=mid-1 else: l=mid+1 return ans n=int(input()) a=list(map(int,input().split())) for i in range(1,n): a[i]=a[i]+a[i-1] q=int(input()) l=list(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
interval = [] pilha = 1 n_pilhas = int(raw_input()) qtd_por_pilha = raw_input().split(" ") n_suculentos = int(raw_input()) rotulos_suc = raw_input().split(" ") for i in range(n_pilhas): aux = int(qtd_por_pilha[i]) for j in range(aux): interval.append(pilha) pilha += 1 for k in range(n_suculentos): aux = 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.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; public class Worms { public static void main(String[] args) { InputReader ir = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = ir....
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 str[100009]; int main(void) { int n, m; scanf("%d", &n); str[0] = 0; for (int i = 1; i <= n; i++) { int c; scanf("%d", &c); str[i] = str[i - 1] + c; } scanf("%d", &m); while (m--) { int c; scanf("%d", &c); if (str[n - 1] < c) { printf("%d\n", 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
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x = 0; cin >> n; int a[n], l[n]; for (int i = 0; i < n; i++) { cin >> a[i]; x += a[i]; l[i] = x; } cin >> m; int q[m]; for (int i = 0; i < m; i++) { cin >> q[i]; cout << lower_bound(l, l + n, q[i]) - l + 1 << 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; template <class T> void readAll(T& vec) { for (auto& i : vec) { cin >> i; } } int binarySearch(vector<int> arr, int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] >= x && arr[mid - 1] <= x) return mid + 1; if (arr[mid] >= x) 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
n=int(input()) a=[int(x) for x in input().split()] lookup=[] m=0 for x in a: m+=1 for i in range(x): lookup.append(m) s=int(input()) b=[int(x) for x in input().split()] for x in b: print(lookup[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
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> pilesQ, pilesAc; for (int i = 0; i < N; i++) { int temp; cin >> temp; pilesQ.push_back(temp); } int sum = 0; for (int i = 0; i < pilesQ.size(); i++) { sum += pilesQ[i]; pilesAc.push_back(sum); } ...
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 input = sys.stdin.buffer.readline a = int(input()) b = list(map(int,input().split())) c = int(input()) d = list(map(int,input().split())) k = [] g = sum(b) t = [0 for x in range(g+1)] p = 1 h = 1 for y in b: for x in range(p,p+y): t[x] = h p += y h += 1 for y in d: print(t[y])
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
// @uthor -: puneet // TimeStamp -: 4:08 PM - 10/10/19 import java.io.*; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.InputMismatchException; import java.util.List; public class Worms implements Runnable { public void solve() { int n=in.ni(); ...
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 bsearch(arr,element): start = 0 end = len(arr)-1 while start <= end: mid = (start+end)//2 mid_element = arr[mid] if element < mid_element: end = mid - 1 elif element > mid_element: start = mid + 1 else: return mid + 1 if 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
n = int(input()) a = [int(x) for x in input().split()] lookup = [] group_no = 0 for x in a: group_no += 1 for i in range(x): lookup.append(group_no) m = int(input()) b = [int(x) for x in input().split()] for x in b: print(lookup[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
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; int* a = new int[n + 1]; int* sum = new int[n + 1]; sum[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } cin >> m; int* q = new int[m]; for (int j = 0; j < m; j++) { cin >> q[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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; public class Worm { public static void main(String[] args)throws IOException { String c = ""; BufferedReader br = new BufferedReader(new InputStreamReader...
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 n = int(raw_input()) piles = map(int, raw_input().split()) m = int(raw_input()) juicy = map(int, raw_input().split()) cs = [0 for i in xrange(n)] cs[0] = piles[0] for i in range(1,n): cs[i] = piles[i]+cs[i-1] for i in juicy: print bisect.bisect_left(cs,i)+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 bisect n=int(input()) a=[int(x) for x in input().split()] m=int(input()) b=[int(x) for x in input().split()] c=[a[0]] for i in range(n-1): c.append(c[i]+a[i+1]) for i in range(m): print(bisect.bisect_left(c,b[i],0,n)+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, x, s = 0; vector<int> v; cin >> n; while (n--) { cin >> x; s += x; v.push_back(s); } cin >> m; while (m--) { cin >> x; cout << lower_bound(v.begin(), v.end(), x) - v.begin() + 1 << endl; } return 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
#include <bits/stdc++.h> using namespace std; int n; int a[100010], sum[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sum[1] = 1; for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i - 1]; int q; scanf("%d", &q); for (; q--;) { int x; scanf("%d", &x); ...
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.*; import java.util.Arrays; import java.util.Scanner; public class B474 { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); ...
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; const int N = 3e5 + 5; long long a[N]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { a[i] += a[i - 1]; } int q; cin >> q; while (q--) { int tot; cin >> tot; int ind = lower_bound(a, 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
from sys import stdin def main(): arr=[] cnte=1 cnte2=1 arr.append(int(0)) stdin.readline() for i in map(int,stdin.readline().split()): for j in range(0,i): arr.append(cnte2) cnte2=cnte2+1 stdin.readline() for i in map(int,stdin.readline().split()): pr...
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 num[1000010]; int main() { int T, n, m, p; int i, j; int cnt = 1; while (~scanf("%d", &T)) { for (i = 1; i <= T; i++) { scanf("%d", &n); for (j = 1; j <= n; j++) num[cnt++] = i; } scanf("%d", &m); for (i = 1; i <= m; i++) { scanf("%d", &p); pr...
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
''' ___ ___ ___ ___ ___ ___ /\__\ /\ \ _____ /\ \ /\ \ /\ \ /\__\ /:/ _/_ \:\ \ /::\ \ \:\ \ ___ /::...
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 = 1e5 + 5; int n, q, l; int A[N], sum[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", A + i); sum[i] = sum[i - 1] + A[i]; } scanf("%d", &q); while (q--) { scanf("%d", &l); printf("%d\n", lower_bound(sum, sum...
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> int binary(int low, int high, int c[], int b) { int pos; if (low > high) pos = 0; else { int mid = (low + high) / 2; if (c[mid] == b) { pos = mid + 1; } else if (b < c[0]) { pos = 1; } else if (b > c[mid] && b < c[mid + 1]) { pos = mid + 2; } 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
from sys import stdin, stdout cin = stdin.readline cout = stdout.write mp = lambda: list(map(int, cin().split())) #binary search didn't work, so sad ''' def binSearch(x): low = 0 high = n-1 while low <= high: mid = (high+low)//2 if x > l[mid]: low += 1 elif x < l[mid]: high -= 1 else: return mid+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()) list1 = list(map(int, input().split(' '))) list2 = [] cou = 1 for i in list1: # идёи по количеству добавлений for k in range(i): list2.append(cou) cou += 1 k = int(input()) list3 = list(map(int, input().split(' '))) for i in range(k): print(list2[list3[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
input() ls=list(map(int, input().split())) bar=[] lab=1 for size in ls: bar+= [lab]*size lab+=1 input() qs=map(int, input().split()) for q in qs: print(bar[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
n=int(input()) def getAns(k,arr,start,end): # if end>n: # return n-1 if start>=end: return end mid=(start+end)//2 if arr[mid]==k: return mid; elif arr[mid]>k: # if mid-1>=0 and arr[mid-1]<k: # return mid-1; return getAns(k,arr,start,mid) elif arr[mid]<k: # if mid+1<n and arr[mid+1]>k: # return ...
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.IOException; import java.io.InputStreamReader; import java.io.FileReader; import java.util.Arrays; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-...
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 binsearch(prefix, ele, n): l, r = 0, n while l <= r: mid = l+(r-l)//2 if ele <= prefix[mid] and ele > prefix[mid-1]: return mid elif ele > prefix[mid]: l = mid+1 else: r = mid-1 return -1 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
from bisect import bisect_left def BinarySearch(a, x): i = bisect_left(a, x) #if i != len(a) and a[i] == x: print (i+1) n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1] for items in b: BinarySearch(a,items)
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 buscaBinaria(procurado, lista, inicio, fim): while (inicio <= fim): meio = (inicio + fim) / 2 e = lista[meio] if e < procurado: inicio = meio + 1 elif e > procurado: fim = meio - 1 else: return meio return inicio piles = int(raw_input()) numberOfWorms = raw_input().s...
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 bin_search(x,lista): meio = (len(lista))/2 inicio = 0 fim = len(lista) while inicio < fim: if lista[meio] < x: inicio = meio + 1 elif lista[meio] > x: fim = meio else: return meio meio = (inicio + fim) / 2 return fim n = int(raw_input()) a = map(int,raw_input().split()) m = int(raw_input()) q = map(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
input() d=[] m=1 for i in map(int,input().split()): for j in range(i): d.append(m) m+=1 input() for i in map(int,input().split()): print(d[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
n=int(input()) A=[int(x)for x in input().split()] B=[0]*n for i in range(1,n): A[i]+=A[i-1] m=int(input()) B=[int(x)for x in input().split()] def find(x, q): first = 0 last = len(x) while first < last: mid = (first+last)//2 if x[mid] < q: first = mid+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 bisect import bisect_left # lower_bound n = int(input()) a = list(map(int , input().split())) for i in range(1 , n): a[i] += a[i - 1] m = int(input()) for i in map(int , input().split()): print(bisect_left(a , i) + 1)
PYTHON3