Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int bs(long long int arr[], int l, int r, int x) {
while (l < r) {
int mid = (l + r) / 2;
if (arr[mid] < x)
l = mid + 1;
else {
r = mid;
}
}
return l;
}
int main() {
int n;
cin >> n;
int arr[n];
long long int ans[n];
long long int... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | """
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
for k in q:
for l in range(n):
k -= a[l]
if k<=0:
print(l+1)
break
"""
from bisect import bisect_left
n = int(input())
a = list(map(int,input().split()))
m = int(input(... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | nums = map(int, raw_input('').split(' '))
piles = map(int, raw_input('').split(' '))
nums = map(int, raw_input('').split(' '))
juicy_positions = map(int, raw_input('').split(' '))
starts = [1]
for i in xrange(1, len(piles)):
starts.append(starts[i - 1] + piles[i - 1])
cache = {}
def search(target, piles, starts... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
k=0
l=[]
c=1
for i in range(len(a)):
x=a[i]
for j in range(k,k+x):
l.append(c)
c+=1
k=k+x
t=int(input())
b=list(map(int,input().split()))
for i in b:
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 | n=int(input())
l=[]
r,x=1,0
for k in input().split():
for j in range(int(k)):
l.append(r)
r+=1
q=input()
for j in input().split():
print(l[int(j)-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Worms {
public static void main(String[]args) {
Main.FastReader s=new Main.FastReader();
int n=s.nextInt();
int[]array=new 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 | # Anuneet Anand
def BS(A,x,l,h):
if h-l>0:
m = (l+h)//2
if x<A[m]:
return BS(A,x,l,m)
else:
return BS(A,x,m+1,h)
else:
if x>A[l]:
return h
else:
return l
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))
C = [1]
S = 0
for i in range(n):
S... | 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 | /**
* Created by mohammad on 8/27/16.
*/
import java.util.*;
public class Problem474B {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] worms = new int[n];
worms[0] = sc.nextInt();
for (int i = 1; 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 | '''
Created on Oct 6, 2014
@author: Ismael
'''
n = int(input())
A = list(map(int,input().split()))
q = int(input())
Q = list(map(int,input().split()))
ans = []
prec = 1
iStack = 0
for ai in A:
iStack += 1
for query in range(prec,prec+ai):
ans.append(iStack)
prec = ai
for query in Q:
print(ans[q... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws IOException{
FastReader sc = new FastReader();
int n = sc.nextInt();
int a[] = new int[n+1];
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(0);
for(int i=1;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 | from bisect import bisect_left as bl
n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
asu=[]
asu.append(a[0])
for i in range(1,n):
asu.append(asu[-1]+a[i])
for i in range(m):
print(bl(asu,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 | from bisect import bisect
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
q = [int(x) for x in input().split()]
ranges = [1]
for i in a:
ranges.append(ranges[-1] + i)
ranges.pop()
for i in q:
print(bisect(ranges, 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 | mp = {}
def main():
a,b =-1,0
n = int(input())
line = input() #Read the whole line
x = line.split()
for i in range(n):
a = b
b = b + int(x[i])
for k in range(a+1,b+1):
mp[k] = 1 + i
m = int(input())
line = input()
q = line.split()
for i in range(m):
print(mp[int(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 | #!/usr/bin/python3
def main():
p = int(input())
ps = [int(x) for x in input().split()]
j = int(input())
js = [int(x) for x in input().split()]
worms = [1]*ps[0]
for i in range(1, p):
worms.extend([i+1]*ps[i])
for jw in js:
print(worms[jw-1])
if __name__ == "__main__... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import javafx.util.Pair;
import static java.lang.Double.parseDouble;
import static java.lang.Integer.max;
import static java.lang.Integer.min;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import java.io.BufferedReader;
import java.io.IOExceptio... | 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.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class MainE {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int cengshu = in.nextInt();
//System.out.println(cengshu);
l... | 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()
arr = map(int, raw_input().split())
res = [arr[0]]
for i in arr[1:]:
res.append(res[-1] + i)
from bisect import bisect_left
q = input()
queries = map(int, raw_input().split())
for i in queries:
print bisect_left(res, 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 |
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)/2
# print "mid, lo, hi", 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;
const int N = 100010;
inline void get(int &x) {
char ch = getchar();
x = 0;
while (ch < '0') ch = getchar();
while (ch >= '0') x = x * 10 + ch - '0', ch = getchar();
}
int n, m, x, a[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) get(a[i]), a[i] += a[i ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = input()
a = map(int,raw_input().split())
m = input()
b = map(int,raw_input().split())
f = [0]
for i in range(n):
f += [i+1]*a[i]
for j in b:
print f[j] | 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 search(low,high, check):
mid = (high + low) // 2
while high >= low:
if check(mid):
low = mid + 1
else:
high = mid - 1
mid = (high + low) // 2
return mid
n = int(input())
ai = list(map(int,input().split()))
m = int(input())
qi = 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 java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.math.*;
import org.omg.CORBA.Any;
public class template {
public static void main(String[] args) throws IOException {
Reader scn=new Reader();
int n=scn.nextInt();
int []a=new int[n];
... | 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 = input()
a = map(int, raw_input().split())
aa = [0]
for i in range(n): aa.append(a[i]+aa[-1])
input()
q = map(int, raw_input().split())
print '\n'.join(map(str, [bisect_left(aa, i) for i in q]))
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Scanner;
public class R474B {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
int n = kbd.nextInt();
int[] a = new int[n+1];
a[0] = 1;
for(int i = 1;i<=n;i++) {
a[i] = kbd.nextInt() + a[i-1];
}
int m = kbd.nextInt();
for(int i = 0;i<m;i++) {
Sy... | 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())
b=list(map(int, input().split()))
c=[]
k=1
for i in range(n):
for j in range (a[i]):
c.append(k)
k+=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 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, a[N], pre[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = a[i] + pre[i - 1];
}
int m;
cin >> m;
while (m--) {
int q;
cin >> q;
cout << lower_bound(pre + 1, pre + n + 1, q) - pre <<... | 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 itertools import accumulate
def bs(vals, x):
lo, mid, hi = 0, 0, len(vals) - 1
while( lo < hi ):
mid = (lo + hi) // 2
if(x == vals[mid]):
return mid
elif( x > vals[mid] ):
lo = mid + 1
else:
hi = mid
return lo
n = int(input())
worms ... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, m, a[100001], i, k, l;
int main() {
cin >> n;
cin >> a[0];
for (i = 1; i < n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
cin >> m;
while (m > 0) {
cin >> k;
l = lower_bound(a, a + n, k) - a;
cout << l + 1 << " ";
m--;
}
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 | from sys import stdin
def main():
'''
Name: Kevin S. Sanchez
Code: B. Worms
'''
inp = stdin
n = int(inp.readline())
worms = list(map(int, inp.readline().split()))
J = int(inp.readline())
Jworms = list(map(int, inp.readline().split()))
lunch = list()
for i in range (0,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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> a;
long t, sum = 0;
for (long i = 0; i < n; i++) {
cin >> t;
sum += t;
a.push_back(sum);
}
long q;
cin >> q;
for (long i = 0; i < q; i++) {
cin >> t;
cout << lower_bound(a.begin(), a.end(), t)... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
input()
heaps = list(map(int, input().split()))
input()
numbers = list(map(int, input().split()))
#heaps = [2, 7, 3, 4, 9]
#numbers = [1, 25, 11]
res = [0] * len(numbers)
sums = [heaps[0]]
mask = [1] * heaps[0]
for i in range(1, len(heaps)):
mask += [i+1] * (heaps[i])
sums.append(heaps[i] + sums[-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 | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
MyScanner in = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int readNumbers = i... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = input()
numbers = raw_input().split()
q = input()
questions = raw_input().split()
big_list=[]
for i in range(len(numbers)):
for q in range(int(numbers[i])):
big_list.append(i+1)
for question_num in questions:
print big_list[int(question_num)-1] | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
s=[0]
for i in range(n):
for k in range(a[i]):
s.append(i+1)
for j in q:print(s[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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Forces {
public static void main(String[] args) throws Exception {
FastReader f = new FastReader();
int n = f.nextInt();
Ar... | 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;
inline void normal(long long int& a) { a = (a + 1000000007) % 1000000007; }
inline int modMul(long long int a, long long int b) {
a %= 1000000007, b %= 1000000007;
normal(a), normal(b);
return (a * b) % 1000000007;
}
inline int modAdd(long long int a, long long int b)... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary_search(element, rng):
start = 0
end = len(rng)
while True:
midle = (end - start) // 2 + start
if rng[midle][0] <= element and rng[midle][1] >= element:
return midle + 1
elif rng[midle][0] > element:
end = midle
elif rng[midle][1] < element:
start = midle
p = int(input())
lst = input().sp... | 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
input()
a=list(map(int,input().split()))
b,s=[],0
for i in a:
s+=i
b+=[s]
input()
q=list(map(int,input().split()))
for i in q:
x=bisect.bisect_left(b,i)+1
print(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 | def bin_search(arr,l,r,val):
mid=(l+r)//2
if(arr[mid]>=val and (mid==0 or arr[mid-1]<val)):
return(mid+1)
elif(arr[mid]<val):
return(bin_search(arr,mid+1,r,val))
else:
return(bin_search(arr,l,mid-1,val))
n=int(input())
arr=list(map(int,input().split()))
lst=[arr[0]]
for i in ra... | 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 |
#class heap:
#def __init__(self, first, last):
#self.first = first
#self.last = last
#def __contains__(self, x):
#if self.first <= x <= self.last:
#return True
#else:
#return False
def borders(nums):
prev = 1
for x in nums:
yield prev, prev + x - 1
prev += x
def inside(x, first, last):
retur... | 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()
sp, pos = [], 1
for el in map(int, input().split()):
sp += [pos] * el
pos += 1
input()
for el in map(int, input().split()):
print(sp[el - 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.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Worms {
public static int bS(int[] arr, int target, int s, int e) {
if (e >= s) {
int mid = (s + e)/2;
if (arr[mid] == 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 | import sys
import bisect
n = int(input())
a = []
sum = 0
line = sys.stdin.readline().split()
for j in line:
sum += int(j)
a.append(sum)
m = int(input())
qq = map(int, sys.stdin.readline().split())
for q in qq:
i = bisect.bisect_left(a, q)
print(i + 1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
public class A
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] ranges = new int[n];
int temp = 0;
for(int i=0; i<n; i++)
{
ranges[i] = input.nextInt() + temp;
temp = ranges[i];
}
int m = input.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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, x, y = 0, nums[100000], mseq;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> x;
y += x;
nums[i] = y;
}
cin >> m;
for (long long i = 0; i < m; i++) {
cin >> mseq;
int pos = lower_bound(nums, nums + n, mseq) -... | 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())
a = map(int, raw_input().split())
m = int(raw_input())
b = map(int, raw_input().split())
s = [0] * 100010
s[0] = a[0]
for i in range(1, n):
s[i] = s[i - 1] + a[i]
for i in range(m):
x = b[i]
l = 0
r = n - 1
while l < r:
mid = (l + r) / 2
if s[mid] < x:
... | 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.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 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 binary(arr, k, lo = 0):
hi = len(arr)
while(lo < hi):
mid = (lo + hi)//2
if arr[mid] < k:
lo = mid + 1
else:
hi = mid
return lo
## taking input
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
## ma... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
public clas... | 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 n1[1000005];
int main() {
int n, i, j;
scanf("%d", &n);
int k = 0;
int x = 1;
for (i = 1; i <= n; i++) {
scanf("%d", &k);
for (j = x; j < x + k; j++) n1[j] = i;
x = x + k;
}
int m;
scanf("%d", &m);
while (m--) {
int a;
scanf("%d", &a);
printf("%d\n"... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
_ = input()
q = map(int, input().split())
for i in range(1,n):
a[i] += a[i-1]
for qi in q:
print(bisect_left(a, qi) + 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
def prefix_sum(a):
b=[a[0]]
n=len(a)
for i in range(1, n, 1):
b.append(b[i-1]+a[i])
return b
def bin_src(c,k):
hi=len(c)-1
lo=0
while (lo<hi):
mid = math.floor(((hi +lo) / 2))
if k<=c[mid]:
hi=mid
else:
lo=mid+1
retu... | 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 classA {
public static void main(String[] args)
{
int[] arr = new int[10000001];
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int at = 0;
for(int i = 0; i<n; i++)
{
int a = input.nextInt();
for(int j = 0; j<a; j++) {
ar... | 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()))
k=[]
for i in range(n):
for j in range(a[i]):
k.append(i+1)
m=int(input())
b=list(map(int,input().split()))
for i in b:
print(k[i-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [0] + list(map(int, input().split()))
s = [0] * (n + 2)
for i in range(1, n + 1):
s[i] = s[i - 1] + a[i]
s[-1] = s[-2] + 100
m = int(input())
q = list(map(int, input().split()))
for t in q:
l, r = 0, n + 1
for i in range(300):
mid = (l + r) // 2
if s[mid - 1] < t and t <... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
l,c=0,[0]
for i in range(n):
l+=a[i]
c.append(l)
for i in range(m):
start,end = 0,n
while start<=end:
middle = (start+end)//2
if c[middle]==b[i]:
print(middle)
... | 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, i, j;
cin >> n;
int a[n + 1];
a[0] = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
cin >> m;
while (m--) {
cin >> j;
int l = 1, r = n, m;
while (l < r) {
m = (l + r) / 2;
if (a[m] == 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 | #include <bits/stdc++.h>
int busca(int a[], int n, int k) {
int l = 0;
int r = n - 1;
while (l <= r) {
int m = (l + r) / 2;
if (k >= a[m] && k <= a[m + 1] && m % 2 == 0)
return (m / 2 + 1);
else if (k >= a[m - 1] && k <= a[m] && m % 2 == 1)
return (m / 2 + 1);
else if (k < a[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 | import java.io.*;
public class CF474B {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) throws IOException {
br.readLine();
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | """
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
def binarySearch (arr, l, r, x):
# Check base case
if r >= l:
mid = l + (r - l)//2
# If element is present at the middle itself
if arr[mid][0] <=x and arr[mid][1] >= x:
return mid
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
ns = map(int, raw_input().split())
for i in xrange(1, n):
ns[i] += ns[i - 1]
qn = int(raw_input())
qs = map(int, raw_input().split())
for q in qs:
l, r = 0, n - 1
while l <= r:
m = (l + r) >> 1
if ns[m] >= q:
r = m - 1
else:
l = m + 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 main() {
int n;
cin >> n;
int c[n];
int i, sum = 0;
for (i = 0; i < n; i++) {
int k;
cin >> k;
sum += k;
c[i] = sum;
}
int ind = 0;
int wrms[sum];
for (i = 1; i <= sum; i++) {
if (i > c[ind]) ind++;
wrms[i] = ind + 1;
}
cin ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | 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 B {
static StringTokenizer st;
static BufferedRead... | 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 | """
Online_Judges = Codeforces
Hacker = black_horse2016
Language = Python2.7.10
"""
import bisect
def GOD():
N = int(input())
a = map(int, raw_input().split())
for i in xrange(1, N):
a[i] += a[i-1]
M = int(input())
q = map(int, raw_input().split())
for i in q:
index = bisect.bise... | 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() {
long long int n, m, i;
cin >> n;
long long int a[n];
long long s = 0;
vector<long long int> v;
for (i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
v.push_back(s);
}
cin >> m;
long long int b[m];
for (i = 0; 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 | n = int(raw_input())
total_list = list()
worm_list = [int(x) for x in raw_input().split()]
total_list.append(1)
for i in range(0,n):
total_list.append(total_list[i] + worm_list[i])
#print total_list
from bisect import bisect
def main():
m = int(raw_input())
for q in raw_input().split():
if int(q)==total_list[... | 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 | numPiles=int(input())
arrPiles=input().strip().split()
numWorms=int(input())
arrWorms=input().strip().split()
arrPiles[0]=int(arrPiles[0])
for i in range(1,len(arrPiles)):
arrPiles[i]=int(arrPiles[i])
arrPiles[i]+=arrPiles[i-1]
arr2=[]
for i in range(len(arrWorms)):
arr2.append([int(arrWorms[i]),i])
arr2.so... | 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 Main {
public static int bSearch(int left,int right,int key,int[] arr) {
if (left == right) {
return left+1;
}
if (left == right -1) {
if (arr[left]>= key) {
return left;
}else {
return right;
}
}
int mid = (int)(left+right)/2;
if (arr[mid] >= key ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
sp=list(map(int, input().split()))
for i in range(1, n):
sp[i]=sp[i-1]+sp[i]
t=int(input())
k=list(map(int, input().split()))
for i in k:
l=0
r=n-1
while l!=r:
mid=(l+r)//2
if sp[mid]>=i:
r=mid
else:
l=mid+1
print(l+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | a,b,c,d,e=input(),list(map(int,input().split())),input(),list(map(int,input().split())),[]
for i in range(len(b)):
for j in range(b[i]):e.append(i+1)
for i in d:print(e[i-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.*;
public class S {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
input()
pos = list(map(int, input().split()))
for i in range(1, len(pos)):
pos[i] += pos[i - 1]
input()
q = list(map(int, input().split()))
for i in q:
print(bisect.bisect_left(pos, 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 itertools import accumulate
from bisect import bisect_left
input()
p = list(accumulate(map(int, input().split())))
input()
for w in map(int, input().split()):
print(bisect_left(p, w) + 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_piles = input()
i_thpile = [int(i) for i in raw_input().split()]
if n_piles != len(i_thpile):
raise Exception("Wrong number of piles.")
n_jucy = input()
labels = [int(i) for i in raw_input().split()]
if n_jucy != len(labels):
raise Exception("Wrong number of labels.")
for i in range(1, len(i_thpile)):
i_t... | 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 sys
input=sys.stdin.buffer.readline
t=int(input())
arr=list(map(int,input().split()))
ans=[]
c=0
for x in arr:
c+=x
ans.append(c)
#print(ans)
n=int(input())
arr2=list(map(int,input().split()))
for x in arr2:
#break
l=0
u=t-1
z=0
while l<=u:
mid=(l+u)//2
#print(l,u,mid)
if ans[mid]==x:
print(mid+... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int find(vector<int> &w, int a) {
int i = 0;
int n = w.size() - 1;
while (i < n) {
int mid = (i + n) / 2;
if (a == w[mid]) {
return mid + 1;
} else if (a > w[mid]) {
i = mid + 1;
} else {
n = mid;
}
}
return i + 1;
}
int main(... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.math.*;
import java.io.*;
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);
Task solver = ... | 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 | I=lambda:map(int,raw_input().split())
n=input();a=I();m=input();q=I();b=[0]
for i in range(n):
b.append(b[-1]+a[i])
def f(k,l,r):
if l==r:
return l
else:
c=(l+r)/2
if b[c]<k:
return f(k,c+1,r)
else:
return f(k,l,c)
for i in range(m):
print f(q[... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException{
Reader.init(System.in);
int n = R... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
a = map(int,raw_input().split(' '))
m = int(raw_input())
q = map(int,raw_input().split(' '))
for i in xrange(n):
if(i==0):
pass
else:
a[i]+=a[i-1]
for i in xrange(m):
key = q[i]
l = 0
r = n-1
ans = -1
while(l<=r):
mid = (l+r)/2
if(a[mid]>=key):
ans = mid
r = mid-1
else:
... | 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 | /**
* Created by mohammad on 8/27/16.
*/
import java.util.*;
public class Problem474B {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] worms = new int[n];
worms[0] = sc.nextInt();
for (int i = 1; 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 | import java.util.*;
public class cherv{
public static void main(String args[]) {
Scanner in= new Scanner(System.in);
int n=in.nextInt();
int arr[]=new int[1000000];
int k=0;
int temp=0;
for(int i=0;i<n;i++){
temp=temp+in.nextInt();
while(k<temp){
arr[k]=i+1;
k++;
}
}
int m=in.nextInt(... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
cin >> a[0];
for (int i = 1; i < n; i++) cin >> a[i], a[i] = a[i - 1] + a[i];
long long int m;
cin >> m;
while (m--) {
int b;
cin >> b;
long long int h = n - 1;
long long int l = 0;
bool g = 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 | #!/usr/bin/pypy3
from sys import stdin,stderr
def readInts(): return map(int,stdin.readline().strip().split())
def print_err(*args,**kwargs): print(*args,file=stderr,**kwargs)
def run():
n, = readInts()
ais = readInts()
s = [ 0 for _ in range(10**6+1) ]
cur_ix = 1
pile = 1
for ai in a... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary_search(n, left, right, sums):
index = -1
while (left <= right):
middle = (left + right) / 2
if (n == sums[middle]):
return middle + 1
if (n > sums[middle]):
left = middle + 1
continue
right = middle - 1
index = middle + 1
return index
n = int(raw_input())... | 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;
const int OO = (int)2e9;
const double eps = 1e-9;
int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
vector<int> v;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(N... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
n = int(sys.stdin.readline())
worms = map(int, sys.stdin.readline().split())
m = int(sys.stdin.readline())
juicies = map(int, sys.stdin.readline().split())
juicies_res = dict.fromkeys(juicies)
juicies_sorted = sorted(juicies)
juicies_len = len(juicies)
i = 0
j = 0
while i<juicies_len:
juicy = juicies_sor... | 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=map(int,raw_input().split())
m=int(input())
b=map(int,raw_input().split())
def binary_search(key,a):
l=0
r=len(a)
while(l<r):
mid=l+(r-l)/2
if(a[mid]==key):
return mid+1
elif(a[mid]<key):
l=mid+1
else:
r=mid
return l+1... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
stdin=sys.stdin
def sol1():
n=int(stdin.readline().strip())
a=map(int,stdin.readline().strip().split())
s=[0]*(10**6+1)
curr=0
for i in range(n):
for j in range(a[i]):
s[curr]=i
curr+=1
m=int(stdin.readline())
for q in map(int,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 | #worms codeforces c328
from sys import stdin
def lee():
n=int(stdin.readline())
worms=[int(x) for x in stdin.readline().split()]
m=int(stdin.readline())
labels=[int(x) for x in stdin.readline().split()]
dic=dicc(n,worms)
#print(dic)
imp(dic,labels)
def dicc(n,worms):
num,c=0,0
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 | def search(c,x):
s=0
e=n-1
while s<=e:
h=s+(e-s)//2
if c[h]==x:
return h+1
elif x<c[h]:
e=h-1
else:
s=h+1
return e+2
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
c=[a[0]]
for i in range(1,n):
c.append(c[i-1]+a[i])
for i in range(m):
print(search... | 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 CF_474B {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n+1];
for(int i=1;i<=n;i++) {
a[i]=sc.nextInt();
a[i]+=a[i-1];
}
int m=sc.nextInt();
for(int i=0;i<m;i++) {
int z=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 |
import java.util.*;
import java.io.*;
public class B
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int arr[] = new int[n];
arr[0] = sc.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 | def binarySearch(lst, item):
first = 0
last = len(lst)-1
found = False
while first<=last and not found:
midpoint = (first + last)//2
if lst[midpoint] == item:
found = True
else:
if item < lst[midpoint]:
last = midpoint-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 |
var n = Number(readline());
var A = readline().split(' ').map(Number)
var m = Number(readline());
var Q = readline().split(' ').map(Number)
for (var i = 1; i < n; i++) {
A[i] += A[i-1]
}
var lower_bound = function(A, x) {
var l = 0;
var r = A.length - 1;
while (l <= r) {
var m = M... | 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())
labels = list(map(int,input().split(' ')))
m = int(input())
ans = list(map(int,input().split(' ')))
numbers = [0] * (sum(labels) + 1)
count = 1
i = 1
for x in labels:
for j in range(i,x+i):
numbers[j] = count
count += 1
i = x + i
for i in ans:
print(numbers[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 itertools import accumulate
n = int(input())
l = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
acc = list(accumulate(l))
#print(acc)
ans = []
for i in range(n):
ans.extend([i + 1] * l[i])
for i in q:
print(ans[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())
sep=list(map(int,input().split()))
nums=int(input())
ip=map(int,input().split())
s=sum(sep)
l=[0]*s
step,count=0,1
for i in sep:
for k in range(step,step+i):
l[k]=count
step+=i
count+=1
for i in ip:
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 |
n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
z=[]
for i in range(n):
for j in range(a[i]):
z.append(i+1)
for k in q:
print(z[k-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import math
import bisect as bis
import heapq
M=1000000007
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())
q=[int(i) for i in input().split()]
for e in q:
p=bis.bisect_left(a,e)
print(p+1) | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.