Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from collections import Counter #sys.setrecursionlimit(100000000) inp = lambda: int(input()) strng = lambda: input(...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; public class Solution { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
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 = [] t = [0 for x in range(10**6+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
from bisect import bisect as bs n=int(input()) l=list(map(int,input().split())) a=[0]*n m=0 for i in range(n): m+=l[i] a[i]=m q=int(input()) s=set(a) query=list(map(int,input().split())) for i in range(q): print(bs(a,query[i])+ (1 if query[i] not in s else 0))
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import bisect n = int(input()) c = [0] * (n + 1) for i, x in enumerate(map(int, input().split()), 1): c[i] = c[i-1] + x m = int(input()) for i in map(int, input().split()): print(bisect.bisect_right(c, i-1))
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import sys from math import sqrt mod = 1000000007 n = 1000000 def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline() def print_array(a): print(" ".join(map(str, a))) def bsearch(a, n, p): 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
from sys import stdin def get_closest_binary(num, l): if num > l[-1]: return l[-1] elif num < l[0]: return 0 else: m = 0 ma = len(l) - 1 while ma - m > 1: if num > l[m + ((ma - m) // 2)]: m += ((ma - m) // 2) else: ...
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; public class Worms { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine());...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n=int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) for i in range(1,n): a[i]=a[i]+a[i-1] l=max(q)+1 j=1 ll=[0]*l for i in range(1,l): if i<=a[j-1]: ll[i]=j else: j=j+1 ll[i]=j for i in range(m): x=q[i] print(ll[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
''' # https://www.jdoodle.com/python3-programming-online/ # # 16.07.2021 # # CF 271 B # # ''' n = int (input ()) def Bin (a, b) : left = 0; right = n-1 while left + 1 < right : mid = (left + right) // 2 if a [mid] == b : return mid elif a [mid] < b : left = mid + 1 else : right...
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
array = [0]*(10**6) ##INPUT FROM FILE # with open("input.txt",'r') as f: # n = int(f.readline().rstrip()) # noOfWorms = list(map(int,f.readline().rstrip().split())) # m = int(f.readline().rstrip()) # queries = list(map(int,f.readline().rstrip().split())) # # MAIN CODE/LOGIC n = int(input().rstrip()) ...
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 = list(map(int,input().split())) m = int(input()) t = list(map(int,input().split())) l = [0]*(sum(s)+2) x = 1 for i in range(n): for j in range(s[i]): l[x] = i+1 x+=1 for y in t: print(l[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
#include <bits/stdc++.h> const int INF = 500000001; const double EPS = 1e-9; const double PI = acos(-1.0); using namespace std; int main() { int n, ans[1000005]; int s, e, tmp, m, k, cnt; while (~scanf("%d", &n)) { k = cnt = 1; for (int i = 0; i < n; i++) { scanf("%d", &tmp); for (int j = k; 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 bisect n = int(input()) a = list(map(int, input().split()))[:n] m = int(input()) q = list(map(int, input().split()))[:m] level = [0]*n for i in range(n): if(i==0): level[0] += a[0] else: level[i] = level[i-1]+a[i] # print(level) def myBinSearch(arr, n): # i = 0 length = len(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
a=int(input()) list1=list(map(int,input().split())) b=int(input()) list2=list(map(int,input().split())) list3=[(i+1,list2[i]) for i in range(b)] list3.sort(key=lambda x:x[1]) dic1={} output=[] for i in range(a): dic1[i+1]=(dic1[i][1]+1,dic1[i][1]+list1[i])if i!=0 else (1,list1[0]) count=0 j=1 while 1: flag...
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().strip().split(' '))) aq = [0] for i in range(1, n + 1): aq += [i] * a[i - 1] m = int(input()) q = list(map(int, input().strip().split(' '))) for i in q: print(aq[i])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import os,sys;from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno();self.buffer = BytesIO();self.writable = "x" in file.mode or "r" not in file.mode;self.write = self.buffer.write if self.writable else None def read(self):...
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, i, m, sum = 0; cin >> n; vector<int> v(n); for (i = 0; i < n; i++) { cin >> v[i]; } for (i = 1; i < n; i++) { v[i] = v[i] + v[i - 1]; } cin >> m; long long b[m]; for (i = 0; i < m; i++) cin >> b[i]; for (i = 0; i < m; ...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int presum[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; int su = 0; for (int i = 0; i < n; i++) { presum[i] = su + a[i]; su = presum[i]; } int 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
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int INF = 1e9; const int maxn = 1e5 + 100; struct node { int x, id; } q[maxn]; int n, m; int a[maxn][2]; bool cmpx(node a, node b) { return a.x < b.x; } bool cmpid(node a, node b) { return a.id < b.id; } int ans[maxn]; int main() { scanf("...
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 time #import random ''' n = 100000 seq = range(1000) a = [] for i in range(n): a.append(random.choice(seq)) m = 1000 seq = range(10000000) q = [] for i in range(m): q.append(random.choice(seq)) ''' n = int(input()) a = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) ...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import operator n = int(input()) piles = [int(x) for x in input().split(' ')] m = int(input()) goodWorms = [int(x) for x in input().split(' ')] sortedWorms = sorted(goodWorms) wormDict = {} pileSeries = [] currentSum = 0 previousSum = 0 for i in piles: currentSum += i pileSeries.append((previousSum, current...
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(i) for i in input().split()] m = int(input()) worms = [int(i) for i in input().split()] data = [] for i in range(n): data += [i + 1] * piles[i] for i in worms: print(data[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 special_binary_search(int ara[], int number, int n) { if (number <= ara[0]) return 0; int st = 0, fn = n - 1, i, middle; while (fn - st > 1) { middle = (st + fn) / 2; if (ara[middle] >= number) fn = middle; else st = middle; } return fn...
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 as br n=int(input()) l=list(map(int,input().split())) a=[] s=0 for i in range(n): s+=l[i] a.append(s) m=int(input()) q=list(map(int,input().split())) for i in range(m): x=br(a,q[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 java.util.Arrays; import java.util.Scanner; public class Cdoe474B { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] piles = new int[n + 1]; int[] range = new int[n + 1]; piles[0] = 0; for(int i = 1; i <= n; i++) { pile...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n = int(input()) piles = [int(a) for a in input().split()] q = int(input()) queries = [int(b) for b in input().split()] worms = {} i = 1 for p in range(n): for k in range(piles[p]): worms[i] = p+1 i+=1 for j in queries: print(worms[j])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
mod = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) from bisect import * n=ii() l=il() m=ii() lq=il() lsf=[l[0]] for i in range(1,n): lsf.append(lsf[-...
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
y = int(input()) a = list(map(int,input().split())) b = [] #print(a) for i in range ( len(a) ): for j in range ( a[i] ): b.append( i + 1 ) #print(b) x = int(input()) c = list(map(int,input().split())) for h in range (len(c)): print(b[c[h] - 1]) # lo = 0 # hi = len(a) - 1 # while lo < hi: # mid = (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 bisect import * from itertools import * i, x = input, lambda: [int(x) for x in i().split()] _, a, _ = i(), list(accumulate(x())), i() for i in x(): 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() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); int n, valore, s[100002], m, worm; cin >> n; for (int i = 0; i < n; i++) { cin >> valore; if (i == 0) s[1] = valore; else s[i + 1] = s[i] + valore; } cin >> m; for (int i...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n,a = int(input()), list(map(int, input().split())) m,q = int(input()), list(map(int, input().split())) dp = [] for i in range(n): dp += [i+1]*a[i] for x in q: print (dp[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
n = int(input()) arr = list(map(int,input().split())) m = int(input()) quarr = list(map(int,input().split())) sumarr = [0 for i in range(n)] sumarr[0]=arr[0] for i in range(1,n): sumarr[i] = sumarr[i-1] + arr[i] for w in range(m): q = quarr[w] l = 0 r = n-1 while l<=r: mid = (l+r)//2 if sumarr[mid] >= q: 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
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public stati...
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())) rng = [[1,a[0]]] sm = a[0] for i in range(1,len(a)) : sm += a[i] rng.append([rng[i-1][1]+1,sm]) m = int(input()) q = list(map(int,input().split())) for k in range(m) : i,j = 0,n-1 while i<j : if rng[i][0] <= q[k] and q[k] <= rng[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()) arr = [int(i) for i in input().split()] for i in range(1,n): arr[i]+=arr[i-1] # print(*arr) m = int(input()) q = [int(i) for i in input().split()] for x in q: print(bisect_left(arr,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
L = [] input() r = 1 for k in input().split(): L += [r]*int(k) r += 1 input() for i in list(map(int, input().split())): print(L[i-1])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
L=lambda:map(int,raw_input().split()) def bs(a,n,x): l=0;r=n-1 while l<=r: mid=l+(r-l)/2 if x==a[mid]: return mid elif x>a[mid]: l=mid+1 else: r=mid-1 return l n = int(raw_input()) a = L() for i in range(1,n): a[i]+=a[i-1] m=int(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
import java.util.*; public class Solution { static int search(int arr[] , int key) { int l = 0 , r = arr.length - 1; while(l <= r) { int mid = (l + r)/2; if(arr[mid] == key) return mid; else if(key < arr[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
n = int(input()) a = list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) i = 1 while i<n: a[i] = a[i-1]+a[i] i = i+1 totalLen = a[-1] table = [0]*(totalLen+1) i = 1 j = 0 while i<=totalLen: if i<=a[j]: table[i] = j+1 else: j = j+1 table[i] = j+1 i = i+1 for qut in q: p...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 1; i < n; i++) arr[i] = arr[i] + arr[i - 1]; int q; cin >> q; while (q--) { long lo...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
m=int(input()) m1=list(map(int,input().split())) n=int(input()) n1=list(map(int,input().split())) l=[] k=0 for val in m1: k+=1 for i in range(val): l.append(k) for worms in n1: print(l[worms-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
# Worms n = int(raw_input()) a = map(int, raw_input().split()) sa = [0] for i in range(n): sa += [i + 1] * a[i] m = int(raw_input()) q = map(int, raw_input().split()) for i in q: print sa[i] ''' f = [0] for i in range(n): f += [i+1] * a[i] print f c = input() print c, type(c) d = raw_input() pr...
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 a=int(input()) b=[int(X) for X in input().split()] c=int(input()) d=[int(X) for X in input().split()] e=[] sum=b[0] e.append(sum) for i in range(1,a): sum+=b[i] e.append(sum) for i in range(c): if(d[i]==e[bisect(e,d[i]) - 1]): print(bisect(e,d[i])) else: print(...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import java.util.Scanner; public class Codeforces2{ public static void main(String args []){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int p; int sum[]=new int[n+1]; sum[0]=0; for(int i=1;i<=n;i++) { p=in.nextInt(); sum[i]=sum[i-1]+p; } int m=in.nextInt(); while(m-->0) { int x=in.nextInt(); if(x<=sum[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
n = int(input()) pre = [] row = 1 for i in input().split(' '): for j in range(int(i)): pre.append(row) row += 1 m = int(input()) tasty_worms = [] for i in input().split(' '): i = int(i) print(pre[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; int myf(int s, int e, int o, int sum1[]) { int mid = (s + e) / 2; if (mid == 0) { if (o <= sum1[0]) return 1; else return 2; } else { if ((o <= sum1[mid]) && (o > sum1[mid - 1])) return mid + 1; else if (o > sum1[mid]) re...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n, m, k; while (scanf("%d", &n) != EOF) { a[0] = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); a[i] += a[i - 1]; } scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &k); printf(...
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(item, cumsum): l = 0 r = len(cumsum) while l <= r: m = (l+r)//2 if item == cumsum[m]: return m elif item < cumsum[m]: r = m - 1 else: l = m + 1 return l n = input() a = map(int, raw_input().split(" ")) m = input() q = 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
#include <bits/stdc++.h> using namespace std; long poz[1000005]; int main() { long i, j, n, a, b; cin >> n; cin >> a; for (i = 1; i <= a; i++) poz[i] = 1; for (i = 1; i < n; i++) { cin >> b; for (j = a + 1; j <= a + b; j++) poz[j] = i + 1; a += b; } cin >> n; for (i = 0; i < n; i++) { ci...
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; struct Point { int X; int Y; }; void Search(int point, Point points[], int first, int last) { while (first <= last) { int mid = first + (last - first) / 2; if (point >= points[mid].X && point <= points[mid].Y) { cout << mid + 1 << endl; break; ...
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_search(long long int a[], int n, long long int x) { int left, right, mid; left = 0; right = n - 1; 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 lef...
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.*; public class Worms { static StringTokenizer st; static BufferedReader in; static PrintWriter out; private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.par...
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 ar(): return map(int,raw_input().split()) n=int(raw_input()) a=ar() m=int(raw_input()) q=ar() t=[] j=0 val=0 for i in a: while j<i: t.append(val) j+=1 #print t val+=1 j=0 #print t for i in q: print t[i-1]+1 ##m="""qwertyuiop ##asdfghjkl; ##zxcvbnm,./""" ##m=m.split('\n') ##a...
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.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
a=int(input()) b=input().split() c=int(input()) d=input().split() b=[int(i) for i in b] e=[] k=0 for i in b: e.append(i+k) k=k+i index=1 j=0 m=1 f=[0] while(1): if(j==len(b)): break if(index==e[j]+1): j=j+1 m=m+1 f.append(m) #print(f[index],index) index=index+1 for i ...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
from collections import Counter from collections import defaultdict import math import random import heapq as hq from math import sqrt import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, ...
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 c(d,t,l,h): if l >h: print(l+1) else: m = int((l+h)/2) if d[m] >= t: c(d,t,l,m-1) else: c(d,t,m+1,h) a,l1,b,l2=int(input()),list(map(int,input().split())),int(input()),list(map(int,input().split())) l3=[0]*a l3[0]=l1[0] for i in range(1,a): l3[i]=...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; long long int power(long long int b, long long int e, long long int m) { if (e == 0) return 1; if (e % 2) return ((b % m) * power(((b % m) * (b % m)) % m, (e - 1) / 2, m)) % m; else return power((b % m) * (b % m), e / 2, m) % m; } long long int ncr(long long 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
raw_input() a = [int(i) for i in raw_input().split(" ")] raw_input() b = [int(i) for i in raw_input().split(" ")] c = [1] * a[0] for i in range(1, len(a)): c += [i+1] * a[i] for i in range(len(b)): print c[b[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
# Description of the problem can be found at http://codeforces.com/problemset/problem/474/B n = int(input()) b = [] b.append(0) l_n = list(map(int, input().split())) for i in range(len(l_n)): for _ in range(l_n[i]): b.append(i + 1) _ = input() for v in list(map(int, input().split())): print(b[v])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n = int(input()) l1 = list(map(int, input().split())) m = int(input()) jworms = list(map(int, input().split())) newl, index = [], 1 for i in l1: for j in range(i): newl.append(index) index += 1 for i in jworms: print(newl[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 itertools as it int(input()) a = [0] a.extend(list(it.accumulate(map(int, input().split())))) int(input()) q = list(map(int, input().split())) d = {} for j in range(len(a)): for i in range(a[j - 1] + 1, a[j] + 1): d[i] = j for i in range(len(q)): q[i] = d[q[i]] print(*q, 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.lang.reflect.Array; import java.util.*; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n+1]; a[0] = sc.nextInt(); for (int i = 1; i < n; i++) { a[i] = a[i-1]...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n=int(input()) l=[int(i) for i in input().split()] l1=[] k=1 for i in range(n): l1+=[k]*l[i] k+=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
#include <bits/stdc++.h> using namespace std; int a[100001]; int n, m; void bs(int k) { int p = -1; for (int i = n; i >= 1; i /= 2) { while (p + i < n && a[p + i] <= k) p += i; } if (a[p] == k) cout << p + 1 << endl; else cout << p + 2 << endl; } int main() { int k; cin >> n; for (int i = 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> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long double eps = 1e-9; const int inf = mod; template <typename T> int sign(const T& a) { if (a < 0) return -1; if (a > 0) return 1; return 0; } void...
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()) worms = [int(x) for x in input().split()] wowo = [0] for i,x in enumerate(worms, 1): wowo.extend([i]*x) # print(wowo) input() for q in input().split(): print(wowo[int(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
from bisect import bisect_left def ans(a,b,n,m,): ans = [] px = [a[0]] for i in range(1,n): px.append(a[i] + px[i-1]) for i in range(m): pos = bisect_left(px,b[i]) #ans.append(pos+1) print(pos+1) #return ans n = int(input()) a = [int(i) for i in input().split()] 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
def find(num): low = 0 high = n-1 while low<high: mid = (low+high)//2 if p[mid]>=num: high = mid-1 else: low = mid+1 if p[low]<num: return low+1 else: return low n = int(input()) a = list(map(int,input().split())) m = int(input()) b = list(map(int,input().split())) p = [a[0]] for i in range(1,n): ...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; long long n, m, a[(int)1e6], s[(int)1e6], x; long long ans() { long long st = 0, en = n - 1; while (st < en) { long long mid = (st + en) >> 1; if (s[mid] >= x) en = mid; else st = mid + 1; } return st; } int main() { scanf("%I64d", &n); f...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] wormLocation = new int[1000005]; int n = sc.nextInt(); sc.nextLine(); int wormsAdded = 0; int worm = 0; for (int i = 0; i < n; i++) {...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
def findWorm (worm, Piles, bottom, top): midIndex = (top+bottom)/2 #assert (0 < midIndex < len(Piles)) if worm <= Piles[midIndex] and (midIndex == 0 or worm > Piles[midIndex-1]): return midIndex #Pile to the left elif worm < Piles[midIndex]: return findWorm(worm, Piles, bo...
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
num = int(input()) piles = list(map(int, input().split(' '))) tuplex = [] curr = 1 for i in piles: tuplex.append((curr, curr+i-1)) curr = curr+i quer = int(input()) queries = list(map(int, input().split(' '))) quer2 = [[queries[x], x, -1] for x in range(len(queries))] quer2.sort(key = lambda x:x[0]) ind = 0 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
n=int(input()) a=list(input().split()) s=[] s.append(0) cnt=1; for i in a: y=int(i) for j in range(y): s.append(cnt) cnt+=1 q=int(input()) x=list(input().split()) for i in x: print(s[int(i)])
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int va[100010]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 1; i <= n; i++) { scanf("%d", &va[i]); va[i] += va[i - 1]; } int m, t; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &t); printf("%...
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()) x = [int(x1) for x1 in input().split()] m=int(input()) q = [int(x1) for x1 in input().split()] for i in range (1,n): x[i]+=x[i-1] 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
#include <bits/stdc++.h> using namespace std; int piles[100000], n, worms, t; int getPile(int h) { int minn = 0; int maxx = n; while (maxx - minn > 1) { int med = (maxx + minn) / 2; if ((piles[med] >= h && med == 0) || (piles[med] >= h && piles[med - 1] < h)) return med + 1; if (piles[me...
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.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; public class Main { int[] borders; int search(int elem) { int index = Arrays.binarySearch(...
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())) d = {} k = 1 for i in range(n): for j in range(a[i]): d[k] = i + 1 k += 1 m = int(input()) q = list(map(int, input().split())) for i in range(m): print(d.get(q[i]))
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
# maa chudaaye duniya from bisect import bisect_left n = int(input()) arr = list(map(int, input().split())) for i in range(1, n): arr[i] += arr[i-1] m = input() for i in list(map(int, input().split())): print(bisect_left(arr, i) + 1)
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
l = input() aa = map(int, raw_input().split()) m = input() qq = map(int, raw_input().split()) ans = [-1] c = 1 for i in aa: for j in xrange(i): ans.append(c) c += 1 for i in qq: print ans[i]
PYTHON
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
def binsearch(arr,elem): first=0 last=len(arr)-1 while first<=last: mid=(first+last)//2 if elem>arr[mid-1] and elem<=arr[mid]: break elif arr[mid]>elem: last=mid-1 else: first=mid+1 return mid def main(args): n=int(input()) l=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
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Worms { public static void main(String[] args) throws IOE...
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=input() num_per_pile=map(int,raw_input().split(" ")) m=input() juicy_nos = map(int,raw_input().split(" ")) for i in range(1,n): num_per_pile[i]+=num_per_pile[i-1] #print num_per_pile flag=False index = -1 start =0 end = n-1 holds=[] ''' for j in range(m): flag=False search = juicy_nos[j] start =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
import bisect # input input() piles = list(map(int, input().split())) for i in range(len(piles)-1): piles[i+1] += piles[i] input() worms = list(map(int, input().split())) # binary search # def bsearch(lo, hi, piles, question): # mid = (lo + hi)//2 # if (piles[mid - 1] < question <= piles[mid]): # ...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
def func(x,k): l=0 r=len(x) while(l<=r): m=int((l+r)/2) if(k==x[m]): return m+1 elif(k>x[m]): l=m+1 else: r=m-1 return l+1 n=int(input()) a=list(map(int,input().split(" "))) m=int(input()) q=list(map(int,input().split(" "))) x=[] sum=0 ...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n = int(input()) a = [1] + list(map(int, input().split())) m = int(input()) q = list(map(int, input().split())) for i in range(1, n + 1): a[i] += a[i - 1] i = 0 d = dict.fromkeys(q, 0) for el in sorted(d): while el >= a[i]: i += 1 d[el] = i res = [] for el in q: res += [str(d[el])] print("\n"...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
def buscarMaior(numElemEmCadaPilha, elem, inicio, fim): if(fim>=inicio): metade = (inicio+fim)/2 if(numElemEmCadaPilha[metade]>=elem): if(metade==0 or numElemEmCadaPilha[metade-1]<elem): return metade ...
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 Testing { public static void main(String args[]) { int c, first, last, middle, n, search, array[]; Scanner s = new Scanner(System.in); n = s.nextInt(); array = new int[n]; array[0] = s.nextInt(); for (c = 1; c < n; c++) array[c] = s.nextInt() +...
JAVA
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
n=input() A=list(int(i) for i in input().split()) m=input() Q=list(int(i) for i in input().split()) piles=[] i = 1 for wnum in A: piles += [i]*wnum i += 1 for q in Q: print(piles[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 bisect n = input() a = map(int, input().split(" ")) m = input() q = map(int, input().split(" ")) p = [0] for ai in a: p.append(p[-1] + ai) for qi in q: i = bisect.bisect_left(p, qi) print(i)
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[1000009], j = 1, m; memset(arr, 0, sizeof arr); cin >> n; for (int i = 1; i <= n; i++) { int a; cin >> a; for (int k = 0; k < a; k++) { arr[j++] = i; } } cin >> m; for (int i = 0; i < m; i++) { int a; cin >...
CPP
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
#include <bits/stdc++.h> using namespace std; long long cs[100001], a, q, i, t, s, e, m, mp, f, n; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a; if (i > 0) cs[i] = cs[i - 1] + a; else cs[i] = a; } cin >> q; while (q--) { s = 0; e = n - 1; mp = 0; m = 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
def binary_search(a, x): ans = 0 start = 0 end = len(a)-1 while start < end: mid = int((start+end)/2) if a[mid] == x: return (mid+1) elif a[mid] > x: ans = mid end = mid elif a[mid] < x: ans = mid+1 start = mid+1 return (ans+1) n = int(input()) a = [int(i) for i in input().split()] for i in...
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import bisect n=int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) a1=a[0] l=[1,a1] for i in range(1,n): l.append(a1+1) a1=a1+a[i] l.append(a1) #print(l) ans=[] for i in q: x=bisect.bisect(l,i) #print(i,x) if x%2==0: ans.append(x//2) 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
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, m, n, val, t = 0, test, arr[100000] = {0}, sum = 0; cin >> n; for (i = 1; i <= n; i++) { scanf("%d", &arr[i]); arr[i] += arr[i - 1]; } cin >> m; for (i = 0; i < m; i++) { scanf("%d", &val); int maxi = n, mini = 1, 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 bisect n = int(input()) a = map(int, input().split()) b = [1] for x in a: b.append(b[-1]+x) m = int(input()) c = map(int, input().split()) for x in c: print(bisect.bisect(b, x))
PYTHON3
474_B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
2
8
import java.util.*; import java.io.*; import java.lang.*; public class MyClass { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String s[] = b...
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 f=lambda:map(int,raw_input().split()) n,a,m,q=input(),f(),input(),f() for i in range(1,n): a[i]+=a[i-1] for i in q: print bisect.bisect_left(a,i)+1
PYTHON