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
# ref: http://www.cnblogs.com/dwtfukgv/p/5665414.html # ref: https://blog.csdn.net/u012377575/article/details/39852769 # 预处理出每堆的上界二分查找答案 ''' #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1e5 + 5; int a[maxn]; int main(){ int n, m; cin >> n; for(int i = 1; i <= n; +...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> int main() { int n, i, a[1000000], k, j = 1; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &k); while (k--) { a[j] = i + 1; j++; } } int m; scanf("%d", &m); while (m--) { int g; scanf("%d", &g); printf("%d\n", a[g]); } 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
# ossan def bin_search(li, k, l, h): m = (l + h) // 2 if k == li[m]: return m+1 elif li[m-1] < k < li[m] and m != 0: return m+1 elif k < li[m] and m == 0: return m+1 elif k > li[m] and m == len(li)-1: return m+1 elif k > li[m]: return bin_search(li, k, 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
from sys import stdin,stdout,setrecursionlimit from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm , accumulate from bisect impor...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
from sys import stdin, stdout from bisect import * input = stdin.read() n, ai_str, m, qi_str = filter(None,input.split('\n')) a = list(map(int, ai_str.split())) q = list(map(int, qi_str.split())) assert len(a) > 0 and len(q) > 0 b = [0] * len(a) for i, ai in enumerate(a): b[i] = b[i-1] + ai for qi in q: print(bis...
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 = input() p = map(int, raw_input().split()) arr = [0] itr = 1 val = 1 for r in p: for i in xrange(itr, itr + r): arr.append(val) itr = r + 1 val += 1 q=input() z=map(int, raw_input().split()) for value in z: print arr[value]
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; vector<bool> isprime(1000007 + 1, true); int small[1000007 + 1]; void sieve() { isprime[0] = isprime[1] = 0; int i, j; for (i = 4; i <= 1000007; i += 2) isprime[i] = 0; for (i = 3; i <= 1000; i += 2) if (isprime[i]) for (j = i * i; j <= 1000007; j += (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 n = int(raw_input()) intervals = map(int,raw_input().split()) m = int(raw_input()) worms = map(int,raw_input().split()) for i in range(1,n): intervals[i] = intervals[i - 1] + intervals[i] for worm in worms: print bisect.bisect_left(intervals,worm) + 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
from bisect import bisect_left as b n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) l = [1] cur = 0 for i in a: cur += i l.append(cur) for i in q: print(max(1, b(l, 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()) s=input().split() m=int(input()) p=input().split() l=[] c=0 for i in range(n): j=0 while(j<int(s[i])): l.append(i) j+=1 for i in range(m): print(l[int(p[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
a = map(int, input().split()) b = list(map(int, input().split())) c = map(int, input().split()) d = list(map(int, input().split())) pos = 1 ans = [] for i in b: ans+=[pos] * int(i) pos += 1 for j in d: print(ans[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 search(a, e): indx = len(a) // 2 mn = 0 mx = len(a) - 1 while True: if mx - mn == 1: indx = mn if indx == mx else mx if a[indx - 1] < e <= a[indx]: return indx else: if e > a[indx]: mn = indx indx = ((mn + mx...
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()) """ 5 2 7 3 4 9 3 1 25 11 idx 0 1 2 3 4 5 prefix_sums: 0 2 9 12 16 25 """ prefix_sums = [0] curr_sum = 0 for i in xrange(len(a)): curr_sum+=a[i] prefix_sums.append(curr_sum) #check: if ...
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.math.*; import java.util.*; public class A { FastScanner in; PrintWriter out; void solve() { int n = in.nextInt(); int[] a = new int[1000001]; int ai = 1; int ax = 1; while (0 < n--) { int tmp = in.nextInt(); whi...
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
# cook your dish here import bisect n=int(input()) nn=list(map(int,input().rstrip().split())) m=int(input()) mm=list(map(int,input().rstrip().split())) summ=0 for i in range (n): summ+=nn[i] nn[i]=summ for i in mm : print(bisect.bisect_left(nn, 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()) worms = list(map(int, input().split())) m = int(input()) end_indices = [worms[0]] for j in worms[1:]: end_indices.append(end_indices[-1] + j) succulent_worms = list(map(int, input().split())) for j in succulent_worms: print(bisect_left(end_indices, j) + 1)
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n= int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) pref = [0 for i in range(n)] pref[0]=a[0] for i in range(1,n): pref[i]=pref[i-1]+a[i] pref=[0]+pref for x in q: l=0 r=n while l<=r: mid=(l+r)//2 if x>pref[mid] and x<=pref[r]: 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
# https://vjudge.net/contest/339400#problem/H n = int(raw_input()) n_worms = list(map(int, raw_input().split(' '))) m = int(raw_input()) qs = list(map(int, raw_input().split(' '))) def sol(nums, lo, hi, q): while lo < hi: mid = (hi - lo) / 2 + lo v = nums[mid] if v == q: return ...
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=input().split() a=list((int(it) for it in a)) m=int(input()) q=input().split() q=list((int(it) for it in q)) sum1=0 ans=0 d=[] for j in range(n): sum1+=a[j] d.append(sum1) #print(d) def find(a, target) : st = 0 end = len(a) - 1; while st <= end: mid = (st + end) /...
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.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Created by dtnha on 10/18/2017. */ public class Worms { private static class Reader { static BufferedReader reader; static StringTokeni...
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
/* * 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.Arrays; import java.util.Scanner; /** * * @author Roger Flores Vargas */ public class Worms { public static v...
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(input()) A = [int(i) for i in input().split()] m = int(input()) Q = [int(i) for i in input().split()] for i in range(n-1): A[i+1] += A[i] for i in Q: m = bisect.bisect_left(A,i)+1 print(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
from bisect import bisect_left n=int(input()) ai=[int(x) for x in input().split()] m=int(input()) mi=[int(x) for x in input().split()] for i in range(1,n): ai[i]=ai[i-1]+ai[i] def getPile(m): low=0 high=n-1 while low<=high: mid=(low+high)//2 if m<ai[mid]: high=mid-1 elif m>ai[mid]: lo...
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 x = int(input()) li = list(map(int, input().split())) y = int(input()) li1 = list(map(int, input().split())) for i in range(1,x): li[i] += li[i-1] for i in li1: #print(bisect_left(li, i, 0, x) + 1)#both works print(bisect_left(li,i) +1 ) #time comlexity 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()) # x = [int(elem) for elem in input().split(" ")] x = list(map(int, input().split(' '))) m = int(input()) # y = [int(elem) for elem in input().split(" ")] y = list(map(int, input().split(' '))) z = [0]*n count = 0 for j in range(n): count += x[j] z[j] = count for i in range(m): l=-1 r=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 bisect import bisect_left n = int(raw_input()) worms = map(int, raw_input().split()) m = int(raw_input()) marr = map(int, raw_input().split()) for i in range(1,len(worms)): worms[i] += worms[i-1] #print worms def function(val): lo = 0 hi = len(worms) -1 while (lo < hi): mid = (lo + hi)/...
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 BS(A,x,l,h): if h>=l: m=(l+h)//2 if A[m-1]<x<=A[m]: return m elif x<A[m]: return BS(A,x,l,m) elif x>A[m]: return BS(A,x,m,h) return 1 n=int(input()) A=list(map(int,input().split())) m=int(input()) B=list(map(int,input().split())) s=0 C=[]...
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 P2 { public static void main (String[] args){ Scanner sc = new Scanner(System.in); int n =sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int c[]=new int[n]; int sum=0; for(int i=0;i<n;i++) { sum+=a[i]; c[i]=sum; } int k =sc....
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 bb(num,lista): inicio = 0 fim = len(lista) ind = 0 while inicio <= fim: meio = (inicio + fim) / 2 if lista[meio] == num: return meio + 1 if lista[meio] < num: inicio = meio + 1 if inicio > ind: ind = inicio ...
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.*; public class B { public static void main(String args[]) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); int[] A=new int[n+1]; String[] S=br.readLine().split("...
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 lines = stdin.read().split('\n') n = int(lines[0]) a = list(map(int, lines[1].split(' '))) for i in range(1, len(a)): a[i] += a[i-1] m = int(lines[2]) qs = list(map(int, lines[3].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
#include <bits/stdc++.h> using namespace std; int d[100][100], i, j, k = 1, t, n, m, a[1111111], b, x, s; char ch; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> x; s = s + x; for (j = 1; j <= x; j++) { a[k++] = i; } } cin >> m; for (i = 1; i <= m; i++) { cin >> b; cout...
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(aux) for aux in input().split()] a = [0] + a for i in range(2, n+1): a[i] += a[i-1] m = int(input()) queries = [int(aux) for aux in input().split()] for i in range(0, m): q = queries[i] l = 1 r = n while(l <= r): mid = (l + r) // 2 if (a[mid] >= q): r = mid-1 else: l = mid...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int prf[n + 1]; prf[0] = 0; for (int i = 1; i <= n; i++) { cin >> prf[i]; if (i > 0) prf[i] += prf[i - 1]; } int q, f; cin >> q; while (q--) { cin >> f; int l = 0, r = n, m; while (r - l > 1) { m ...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
l=[] input() r=1 for k in input().split(): l+=[r]*int(k) r+=1 input() for j in input().split(): print(l[int(j)-1])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n,a = input(),map(int,raw_input().split()) m,tests = input(),map(int,raw_input().split()) f = [0] for i in range(len(a)): for j in range(a[i]): f.append(i+1) for i in tests: print(f[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> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long int n, x; cin >> n; long int a[n]; cin >> a[0]; for (long int i = 1; i < n; i++) { cin >> x; a[i] = a[i - 1] + x; } long int m; cin >> m; while (m--) { cin >> x; long in...
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 find(b,a,start,end,le): mid=int((start+end)/2) if(mid==le-1): print(mid) return mid if(a[mid]<b and b<=a[mid+1]): return mid+1 if(b==a[mid]): return mid; if(a[mid+1]<b): return find(b,a,mid,end,le) if(a[mid]>b): return find(b,a,start,...
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 binarySearch(int* arr, int start, int end, int x) { if (start > end) { return -1; } int mid = (start + end) / 2; if (arr[mid] >= x && (mid == 0 || arr[mid - 1] < x)) return mid; if (arr[mid] > x) { return binarySearch(arr, start, mid - 1, x); } 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 binarysearch(a,x): lo=0 hi=len(z)-1 while lo < hi: mid = (lo + hi) // 2 if a[mid]==x: return mid+1 if a[mid] < x: lo = mid + 1 else: hi = mid return lo+1 n=int(input()) x=[int(i) for i in input().split()] z=[] z.append(x[0]) for i in range(1,...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
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
#include <bits/stdc++.h> using namespace std; int pos[1000100]; int n, m, x, sum, y; int main() { ios ::sync_with_stdio(false); cin.tie(0); cin >> n; cin >> x; sum = x; y = x; for (int i = 1; i <= x; i++) pos[i] = 1; for (int i = 2; i <= n; i++) { cin >> x; sum += x; for (int j = y + 1; 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
def worm(): L = [] input() r = 1 for k in input().split(): L += [r]*int(k) r += 1 input() for j in input().split(): print(L[int(j)-1]) worm()
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) a[i] += a[i - 1]; int q; scanf("%d", &q); while (q--) { int x; scanf("%d", &x); int pos = lower_bound(a.begin(), 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
import sys def search(Max,new,num): if new[0]>num: return 1 Min =0 Mid = int((Max+Min)/2) while Min<=Max: if new[Mid]==num: return Mid+1 break elif new[Min]==num: return Min+1 break elif new[Mid]<num and new[Mid+1]>num: return Mid+2 break elif new[Mid]<num: Min=Mid+1 else: Max=M...
PYTHON
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int m; cin >> m; int q[m]; for (int i = 0; i < m; ++i) { cin >> q[i]; } int f[n]; int u = 0; for (int i = 0; i < n; ++i) { u = u + a[i]; f[i] = u; ...
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.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws IOException { Buffered...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int a[n + 1], i, j; a[0] = 0; int p[1000001]; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); for (j = a[i - 1] + 1; j <= a[i] + a[i - 1]; j++) p[j] = i; a[i] += a[i - 1]; } int m; scanf("%d", &m); int q; for (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
import java.util.*; import java.io.*; import java.lang.*; public final class codeforces11 { public static void main(String args[])throws IOException { try{ //takign input through IO InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int N = in.readInt()...
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
l=lambda:map(int,raw_input().split()) n=input() a=l() m=input() q=sorted(enumerate(l()),key=lambda (x,y):(y,x)) s=0 j=0 r=[] for i in range(n): s+=a[i] #print s, i, a[i], q[j][1], j while j < len(q) and q[j][1] <= s: r+=[(q[j][0], i+1)] j+=1 print '\n'.join(map(lambda (x,y):str(y),sorted(r))...
PYTHON
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
numOfPiece = int(input()) numOfWorm = [int(x) for x in input().split(" ")] numOfChoose = int(input()) chooseWorm = [int(x) for x in input().split(" ")] c_numOfWorm = []; a = 0; b = [] for i in range (0, len(numOfWorm)): for j in range (0, int(numOfWorm[i])): b.append(i) for i in range (0, numOfChoose): print (b[c...
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, i, otv[1000000], j, a, z, q[100000]; cin >> n; int s = 0; j = 0; for (i = 0; i < n; i++) { cin >> a; z = j + 1; s += a; for (z; z <= s; z++) { otv[z] = i + 1; j++; } } cin >> n; for (i = 0; i < n; i++) cin ...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n = int(input()) a = [int(i) for i in input().split(' ')] x = int(input()) b = [int(i) for i in input().split(' ')] result = [] for idx, i in enumerate(a): result += [idx+1]*i for idx, i in enumerate(b): print(result[i-1])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int i, n, sum = 0, t; vector<int> a; cin >> n; for (i = 0; i < n; i++) { cin >> t; sum += t; a.push_back(sum); } cin >> n; for (i = 0; i < n; i++) { cin >> t; cout << lower_bound(a.begin(), a.end(), t) - a.begin() + 1 << '\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
n = int(input()) a = [0] + list(map(int, input().split())) q = int(input()) k = list(map(int, input().split())) for i in range(1, len(a)): a[i] += a[i - 1] v = [0] * (a[-1] + 1) c = 1 for i in range(1, a[-1] + 1): if i > a[c]: c += 1 v[i] = c for i in k: print(v[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
_ = input() a = [int(s) for s in input().split()] _ = input() juice_worms = [int(s) for s in input().split()] def get_worm_heaps(a, juice_worms): heaps = generate_heaps(a) juice_worm_heaps = [str(find_heap(heaps, worm)) for worm in juice_worms] return juice_worm_heaps def generate_heaps(a): heaps = ...
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 binary_search { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr1 = new int[n]; for(int i=0;i<n;i++) { arr1[i]=sc.nextInt(); } int m = sc.nextInt(); int[] arr2 = new...
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 n=int(input()) a=[int(i) for i in input().split()] for i in range(1,n): a[i]+=a[i-1] m=int(input()) b=[int(i) for i in input().split()] for i in b: print(bisect_left(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
#include <bits/stdc++.h> using namespace std; long int a[100000], n; int main() { long int i, m, x, ind; long int a[100000], n; vector<long int> v; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 1; i < n; i++) { a[i] = a[i] + a[i - 1]; } cin >> m; for (i = 0; i < m; i++) { c...
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()) k=input().split() s=list() t={} O=0 q=0 p=int(k[q]) for i in range (n): for (j) in range(int(k[i])): s.append(O+1) O+=1 for l in range (len(s)): if l+1 <= int(p): t[l+1]=q+1 elif l==len(s): q+=1 t[l+1]=q+1 else: q+=1 t[l+1]=q+1 ...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solver { public static void main(String[] Args) t...
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 search(w, n): begin = 0 end = n while(begin <= end): mid = (begin + end)/2 if piles_aux[mid] > w: end = mid - 1 elif piles_aux[mid] < w: begin = mid + 1 else: return mid + 1 return begin + 1 n = int(raw_input()) piles = map(int...
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 Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); ...
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 maximus { public static void main(String [] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int array[]=new int [n+1]; int sum=0; for(int i=1;i<=n;i++){ array[i]=in.nextInt(); sum+=array[i]; array[i]=sum; } int temp[]=new int[sum+1]; int ptr=0; for(int i=1;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
# your code goes here import sys def cal(start,end,keyval): mid=(start+end)/2 if(sol[mid]>=keyval and sol[mid-1]<keyval): return mid elif(sol[mid]>keyval): return cal(start,mid-1,keyval) else: return cal(mid+1,end,keyval) n=int(sys.stdin.readline()); a=map(int,sys.stdin.readline...
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(raw_input()) w = raw_input().split() a = [1] * (n + 1) for i in range(n): a[i + 1] = a[i] + int(w[i]) m = int(raw_input()) w_s = raw_input().split() if (n == 1): for i in range(m): print(1) for i in range(m): mid = len(a) // 2 low = 0 high = len(a) - 1 value = int(w_s[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 = raw_input n = int( input() ) a = map(int, input().split()) m = int( input() ) q = map(int, input().split()) b = list() b.append( a[0] ) for i in xrange( 1, n ): b.append( b[i-1] + a[i] ) def fnd( z, l1, l2 ): global b ind = (l2 + l1) // 2 if z <= b[ind] and ( ind == 0 or z > b[ind-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
#include <bits/stdc++.h> using namespace std; int a[100001], w[1000001]; int main() { int n, m, q; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] = a[i] + a[i - 1]; for (int j = a[i - 1] + 1; j <= a[i]; j++) { w[j] = i; } } cin >> m; for (int i = 1; i <= m; i++) { 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
from bisect import * n = int(input()) a = list(map(int, input().split())) for i in range(n - 1): a[i + 1] += a[i] q = input() for i in map(int, input().split()): print(bisect_left(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
n = int(input()) h = list(map(int, input().split())) a = [] for i in range(len(h)): a += [i for k in range(h[i])] m = int(input()) h = list(map(int, input().split())) for i in h: print(a[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
from bisect import bisect_left a=int(input()) z=list(map(int,input().split())) for i in range(1,len(z)): z[i]+=z[i-1] r=int(input()) ma=list(map(int,input().split())) for i in range(len(ma)): x=bisect_left(z,ma[i]) print(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
import math n=int(input()) a=[] a=list(map(int, input().split())) b=[0] k=0 for i in range(len(a)): k+=1 for j in range(1, a[i]+1): b.append(k) m=int(input()) p=[] p=list(map(int, input().split())) for x in range(len(p)): print(b[p[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
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t, n, x, Q, q; cin >> n; long long a[n]; for (long long i = 0; i < n; ++i) cin >> a[i]; long long sum[n]; sum[0] = a[0]; for (long long i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i]...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
""" n=int(z()) for _ in range(int(z())): x=int(z()) l=list(map(int,z().split())) n=int(z()) l=sorted(list(map(int,z().split())))[::-1] a,b=map(int,z().split()) l=set(map(int,z().split())) led=(6,2,5,5,4,5,6,3,7,6) vowel={'a':0,'e':0,'i':0,'o':0,'u':0} color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OY...
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.util.*; import javax.swing.plaf.synth.SynthSpinnerUI; import javax.swing.plaf.synth.SynthStyle; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer...
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()) a = list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1] k = int(input()) m = list(map(int,input().split())) for i in range(k): l = 0 r = n-1 now = m[i] while r>l: c = (r+l)//2 if a[c]<now: l = c+1 else: r = c print(r+...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) c=[];s=1 for i in range(n): c+=[s]*(a[i]) s+=1 for i in range(m): print(c[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
n = int(input()) piles = [int(a) for a in input().split()] worms = [0] * (sum(piles)+1) amount = 0 for x in range(n): for i in range(amount+1, amount+piles[x]+1): worms[i] = x+1 amount += piles[x] jw = input() for worm in [int(a) for a in input().split()]: print(worms[worm])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
p = int(input()) #no.of piles worms = list(map(int,input().split())) c = int(input()) lab = list(map(int,input().split())) #labels piles = [] a1 =0 for i in range(p) : for j in range(a1+1,a1+worms[i]+1) : piles.append(i+1) a1 = a1 + worms[i] for i in range(c) : print(piles[lab[...
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 binary_search(long long int a[], int n, long long int x) { int left, right, mid, i; left = 1; right = n; while (left <= right) { mid = (right + left) / 2; if (a[mid] == x) return mid; if (a[mid] > x) right = mid - 1; else left = mid + 1; } return left...
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 from itertools import accumulate R = lambda: map(int, input().split()) n = int(input()) ps = list(accumulate(list(R()))) tn = int(input()) ts = list(R()) for t in ts: print(bisect_left(ps, t) + 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(raw_input()) arr=map(int,raw_input().split()) q=int(raw_input()) ques=map(int,raw_input().split()) for i in range(len(arr)): if i==0: continue arr[i]+=arr[i-1] bing=arr[-1] blah=['#'] p=0 val=1 # print arr,bing for i in range(1,bing+1): if i<=arr[p]: blah.append(val) else: blah.append(val+1) p+=1 va...
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; unsigned long long ull; int main() { ull = 0; int n; cin >> n; int *A = new int[n]; for (int i = 0; i < n; i++) { cin >> A[i]; } int m; cin >> m; int zn; vector<pair<int, int> > ip(m); for (int i = 0; i < m; i++) { cin >> zn; ip[i].first = ...
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(raw_input("")) piles = map(int, raw_input("").split()) m = int(raw_input("")) labels = map(int, raw_input("").split()) calculatedPiles = [] currValue = 0 answerList = [] for i in piles: currValue += i calculatedPiles.append(currValue) def findWorm(compareNum): low = 0 high = n - 1 answer ...
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 = list(map(int,input().split())) juicy = int(input()) num = list(map(int,input().split())) b = num.copy() temp = 0 prefixarray = [] for i in range(len(a)): temp = temp+a[i] prefixarray.append(temp) for i in range(len(b)): print(bisect.bisect_left(prefixarray,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
fi = lambda: map(int,input().split()) ii = lambda: int(input()) from itertools import accumulate from bisect import bisect_left n = ii() a = list(accumulate(fi())) m = ii() for i in fi(): print(bisect_left(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
#include <bits/stdc++.h> using namespace std; int main() { long long n, q, a; cin >> n; std::vector<long long> x(n); long long sum = 0; for (long long i = 0; i < n; i++) { cin >> x[i]; sum += x[i]; x[i] = sum; } cin >> q; long long ans = 0; while (q--) { cin >> a; ans = (lower_boun...
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.StringTokenizer; public class CF_474B_Worms { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
def search(q): l, r = 0, len(a) while(l < r): mid = (l + r) // 2 if a[mid] == q: return mid + 1 elif a[mid] < q: l = mid + 1 else: r = mid return l + 1 n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(...
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, sum = 0; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; b[i] = sum; } cin >> m; int c[m]; for (int i = 0; i < m; i++) { cin >> c[i]; cout << lower_bound(b, b + n, c[i]) - b + 1 << ...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import copy n = int(input()) a = list(map(int, input().split())) d = dict () x = 1 for i in range (0, n): for j in range (0, a[i]): d[j + x] = i + 1 x += a[i] m = int(input()) q = (list(map(int, input().split()))) print (*[d[q[i]] for i in range (0, m)], 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
import java.io.InputStreamReader; import java.io.IOException; import java.util.InputMismatchException; import java.io.PrintStream; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; import java.io.InputStream; /** * Built using CHelper...
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(raw_input()) a = map(int, raw_input().split()) m = int(raw_input()) mm = map(int, raw_input().split()) x = sum(a) ans = [0]*x ptr = 1 i = 1 ss = [] sm = 0 for e in a: sm+=e ss.append(sm) while i <= x: if i <= ss[ptr-1]: ans[i-1] = ptr else: ptr+=1 continue i+=1 for e ...
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
L=[] input() r=1 for k in input().split(): L+=[r]*int(k) r+=1 input() for j in input().split(): print(L[int(j)-1]) # The tricky perfect ver. the L[i] is O(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
if __name__ == '__main__': n = int(raw_input()) num_worms_piles = [int(num) for num in raw_input().split()] num_juicy = int(raw_input()) labels_juicy = [int(num)-1 for num in raw_input().split()] piles = [0]*1000000 i = j = 0 for num_worms in num_worms_piles: for k in range(num_wor...
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.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.PriorityQueue; import java.util.Scanner; import java.lang.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int []...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n=int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) a1=[a[0]] for i in range(1,n): a1.append(a[i]+a1[i-1]) l=[0]*(max(q)+1) j=1 for i in range(len(l)): if(i<=a1[j-1]): l[i]=j else: j+=1 l[i]=j #print(a1,l,len(l)) for i in range(m): prin...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
x=int(input()) s=list(map(int,input().split())) z=[] l=1 for n in s: z+=[l]*n l+=1 input() d=list(map(int,input().split())) for n in d: print(z[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
t = int(input()) arr = [int(x) for x in input().split()] t2 = int(input()) arr2 = [int(x) for x in input().split()] arr3=[0]*(10**6+1) prev = 0 c = 1 for i in range(t): a = arr[i] while (a): arr3[c] = i a -= 1 c += 1 for j in arr2: print(arr3[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.util.*; public class Main { public static void main(String[] args) throws IOException { Solution solution = new Solution(); solution.solve(); } } class Solution{ Solution(){ } ...
JAVA