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 main() {
int n;
cin >> n;
vector<int> a(n);
for (auto &x : a) cin >> x;
for (int i = 1; i < n; i++) {
a[i] = a[i] + a[i - 1];
}
int m;
cin >> m;
int t;
while (m--) {
cin >> t;
int j = lower_bound(a.begin(), a.end(), t) - a.begin();
co... | 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();rahat=[0];import bisect
for i in map(int,input().split()):
rahat.append(i+rahat[-1])
input()
for i in map(int,input().split()):
print(bisect.bisect_left(rahat,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.nio.charset.StandardCharsets;
// import java.math.BigInteger;
public class B {
static Writer wr;
public static void main(String[] args) throws Exception {
// long startTime = System.nanoTime();
// String testString = "";
// InputStream... | 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 argc, char const *argv[]) {
long long n, m;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; ++i) cin >> v[i];
vector<long long> a(accumulate(v.begin(), v.end(), 0));
long long p = 0;
for (long long i = 0; i < n; ++i)
for (long l... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long lcm3(long long a, long long b, long long c) {
return lcm(a, lcm(b, c));
}
long long bigmod(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 | #include <bits/stdc++.h>
int main() {
int n, temp, m;
scanf("%d", &n);
int total[n + 1];
total[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &temp);
total[i] = total[i - 1] + temp;
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &temp);
int start = 0, end = n, mid = (in... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
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(bisect_left(c,b[i])+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
lst = list(int(num) for num in input().split())[:n]
m = int(input())
lst1 = list(int(num) for num in input().split())[:m]
lstworm=[]
index=1
for i in range(0,len(lst)):
for j in range(0,lst[i]):
lstworm.append(index)
index+=1
for i in range(0,len(lst1)):
x=lst1[i]
print(lstworm[... | 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;
void solve() {
long long int n;
cin >> n;
std::vector<long long int> v(n);
long long int sum = 0;
for (long long int i = 0; i < n; ++i) {
cin >> v[i];
sum += v[i];
v[i] = sum;
}
long long int m;
cin >> m;
for (long long int i = 0; i < m; ++i) {... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #print(chr(9617))
I = lambda: map(int,input().split())
n = int(input())
a = list(I())
s = 0
start = 1
res = [0] * 1000001
x = 1
for i in range(n):
s+=a[i]
for j in range(start,s+1): res[j] = x
x+=1
start = s + 1
m = int(input())
b = list(I())
for i in range(m):
print(res[b[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 | #In the name of Allah
from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
srt = sorted(zip(q, list(range(m))))
rng = [0] * m
cnt = 0
for (i, j) in srt:
q[cnt] = i
rng[cnt] = j
cnt += 1
r = 0
j = 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 | #include <bits/stdc++.h>
using namespace std;
inline int nxt() {
int a;
scanf("%d", &a);
return a;
}
inline long long int NXT() {
long long int a;
scanf("%lld", &a);
return a;
}
int ara[100010];
int binarysearch(int s, int n) {
int high = n;
int low = 1;
int ans = 1;
while (low <= high) {
int mi... | 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_pile(N, Ai_list, m, labels_list):
for idx in range(1, N):
Ai_list[idx] += Ai_list[idx - 1]
max = Ai_list[-1]
label_mapping = dict()
ptr = 0
for i in range(1, max + 1):
if(i <= Ai_list[ptr]):
label_mapping[i] = ptr + 1
else:
label_mapping[... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Scanner;
import java.math.*;
public class Main {... | 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 as bs
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
for i in range(1,n):
a[i]+=a[i-1]
for i in range(m):
print(bs.bisect_left(a,b[i])+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
ln = map(int, raw_input().split())
ans = [0]*1000002
cnt = 1
for i in xrange(len(ln)):
for j in xrange(ln[i]):
ans[cnt] = i+1
cnt = cnt + 1
#for i in xrange(25):
# print ans[i],
m = int(raw_input())
lm = map(int, raw_input().split())
for j in lm:
print ans[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 | n = int(input())
a = [int(i) for i in input().split()]
pref = [0] * n
k = 0
for i in range(n):
k += a[i]
pref[i] = k
# print(pref)
qs = int(input())
q = [int(i) for i in input().split()]
for x in q:
l, r = -1, n - 1
while l + 1 < r:
m = (l + r) // 2
if pref[m] >= x:
r = m
else:
l = m
print(r + 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 as bl
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
pos = [int(x) for x in input().split()]
for i in range(1, n):
a[i] += a[i-1]
for i in range(m):
print(bl(a, 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 | def main():
x = int(input())
lst1 = list(map(int, input().split()))
y = int(input())
lst = list(map(int, input().split()))
sums = []
for i in range(x):
sums += [i+1]*lst1[i]
for i in lst:
print(sums[i-1])
main() | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
wormst = list(map(int, input().split()))
soma = sum(wormst)
worms = [0] * (soma + 1)
pre = 0
for i in range(len(wormst)):
start = pre + 1
end = start + wormst[i] - 1
pre = end
for k in range(start, end + 1):
worms[k] = i + 1
q = int(input())
queries = 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 | n=int(input())
l=[int(x) for x in input().split()]
m=input()
s=[int(x) for x in input().split()]
lk=[0]*sum(l)
a=0
for i in range(n):
for j in range(l[i]):
lk[a+j]=i+1
a+=l[i]
for i in s:
print(lk[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=[int(x) for x in input().split()]
b=[0]*(n+1)
for i in range (1,n+1):
b[i]=b[i-1]+a[i-1]
m=int(input())
d=[0]*(b[n]+1)
c=[int(x) for x in input().split()]
tmp=1
for i in range (1,b[n]+1):
if(i<=b[tmp]):
d[i]=tmp
else:
tmp+=1
d[i]=tmp
for i in range (m):
print(d[c... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
public class Worms_474B {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum = 0;
int p[] = new int[n];
for(int i =0 ;i<n; i++) {
int temp = sc.nextInt();
sum+=temp;
p[i] = sum;
}
... | 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 | #alphabet = 'abcdefghijklmnopqrstuvwxyz'
n = input()
a = list(map(int, input().split()))
m = input()
q = map(int, input().split())
pos = []
curr = 1
ind = 0
for i in a:
for j in range(i):
pos.append(curr)
ind+=1
curr += 1
for i in q:
print(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 | n = input()
f = lambda: map(int, raw_input().split())
arr = f()
k = input()
arr1 = f()
d = [arr[0]]
for index, val in enumerate(arr[1:]):
d.append(d[-1]+val)
for i in arr1:
l = 0
r = n
while l < r:
mid = l + (r-l)/2
if i <= d[mid]:
r = mid
else:
l = mid ... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long n, m, a[100005], q[100005], RS;
int main() {
ios_base::sync_with_stdio(0);
ifstream fin("test.txt");
cin >> n;
for (long i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1];
cin >> m;
for (long i = 1; i <= m; i++) cin >> q[i];
a[0] = -1, a[n + 1] = 1e9... | 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 b, d, c[100005], e;
int main() {
cin >> b;
for (int i = 0; i < b; i++) {
cin >> c[i];
c[i] += c[i - 1];
}
cin >> d;
for (int i = 0; i < d; i++) {
cin >> e;
cout << (lower_bound(c, c + b, e) - c) + 1 << endl;
}
return 0;
}
| CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin, stdout
def buscaBinaria(lista, inicio, fim, num):
if(fim>=inicio):
meio = (inicio+fim)//2
if(lista[meio] == num):
return meio
elif(lista[meio] < num):
if(lista[meio+1] > num):
return meio+1
else:
return buscaBinaria(lista, meio+1, fim, num)
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 | # number of piles
n = int(input())
# number in each pile
a = []
r = 0
for k in input().split():
a += [r]*int(k)
r += 1
# number of juicy worms
m = int(input())
# label of juicy worms
for x in input().split():
print(a[int(x)-1]+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
a=list(map(int,input().split()))
c=[]
l=0
for i in range(len(a)):
l+=a[i]
c.append(l)
q=int(input())
x=list(map(int,input().split()))
for i in range(len(x)):
t=bisect.bisect_left(c,x[i])
print(t+1,end=' ') | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
a = map(int, raw_input().split())
m = int(raw_input())
q = map(int, raw_input().split())
def binary_search(A, x, i, j):
if i == j:
return i
if A[(i + j) / 2] < x:
return binary_search(A, x, (i + j) / 2 + 1, j)
else:
return binary_search(A, x, i, (i + j) / 2)
s... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
vector<int> vec;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (i == 0)
vec.push_back(x);
else {
vec.push_back(x + vec[i - 1]);... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int sum_pre[100000];
int n, m, v, a;
static int bs(int l, int r) {
if (l == r) return l;
int m = (l + r) / 2;
if (sum_pre[m] < v)
return bs(m + 1, r);
else
return bs(l, m);
}
int main() {
scanf("%d", &n);
scanf("%d", &a);
sum_pre[0] = a;
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 | from bisect import bisect_left
n=int(raw_input())
a=map(int,raw_input().split())
m=int(raw_input())
q=map(int,raw_input().split())
for i in range(1,len(a)):
a[i]+=a[i-1]
for i in q:
print bisect_left(a,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(input())
bookCnt = list(map(int,input().split()))
m = int(input())
serialNum = list(map(int,input().split()))
def findFirstLessThan(arr,l,r,target):
while l<=r:
mid = (l+r)//2
if arr[mid]==target:
return mid+1
elif arr[mid]>target:
r = 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 | import javax.xml.stream.events.Characters;
import java.util.*;
public class Check2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] ar=new int[n];
for(int i=0;i<n;i++){
ar[i]=sc.nextInt();
}
int m=sc.... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary(l,f):
a=0;
b=len(l)-1;
while(a<=b):
m = a+((b-a)//2)
if (l[m]==f):
return m;
if(l[m]<f):
a=m+1;
else:
b=m-1;
if(l[m]<f):
return m+1;
return m;
n=int(input());
shop_price=list(map(int,input().split(" ")));
count=1;... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> a;
vector<long long> res;
int main() {
scanf("%I64d", &n);
for (long long i = 1; i <= n; ++i) {
scanf("%I64d", &m);
for (long long j = 0; j < m; ++j) {
a.push_back(i);
}
}
scanf("%I64d", &m);
for (long long 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 | n=int(input())
arr=list(map(int,input().strip().split(' ')))
m=int(input())
q=list(map(int,input().strip().split(' ')))
lis=[0]
for index,num in enumerate(arr):
lis+=[index+1 for _ in range(num)]
res=[]
for i in q:
res.append(str(lis[i]))
print('\n'.join(res))
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(raw_input())
s = raw_input()
a = [int(x) for x in s.split(' ')]
m = int(raw_input())
s = raw_input()
q = [int(x) for x in s.split(' ')]
for i in xrange(1, n):
a[i] += a[i-1]
for x in q:
print bisect_left(a, x) + 1 | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.util.Arrays;
public class Worms
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
int i,j=0,s=0;
int p[]=new int[2000000];
for( i=0;i<n;i++)
{
s+=sc.nextInt();
while(j<=s)
{
p[j]=i+1;
j++;
}... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.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;
public class worms
{
int binarySearch(int arr[]... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i) cin >> a[i];
int sum[n];
sum[0] = a[0];
for (int i = 1; i < n; ++i) {
sum[i] = sum[i - 1] + a[i];
}
int m;
cin >> m;
while (m--) {
int x;
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def main():
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
acc_a = [0] * n
acc = 0
for i, x in enumerate(a):
acc = acc_a[i] = x + acc
for x in q:
low, high = 0, n-1
while low < high:
mid = (low... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
int const MAX = 1e6 + 5;
int num[MAX];
int main() {
int n;
scanf("%d", &n);
int sum = 0, temp;
int sign = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &temp);
sum += temp;
for (int j = sign; j <= sum; j++) num[j] = i;
sign = sum + 1;
}
scanf("%d", &n);
for (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 | from sys import stdin,stdout
def main():
le=int(stdin.readline())
d={}
pos=1
val=[int(x) for x in stdin.readline().split()]
for k in range(le):
for i in range(val[k]):
d[pos]=k+1
pos+=1
la=int(stdin.readline())
for i in map(int,stdin.readline().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.*;
import java.util.*;
public class qtn2{
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
PrintWriter out = new PrintWriter(new Buffered... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | npiles = int(raw_input())
piles = map(int, raw_input().split())
njuicy = int(raw_input())
juicy = map(int, raw_input().split())
ans = [0]
for i in range(len(piles)):
ans.extend([i+1] * piles[i])
for j in juicy:
print ans[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 |
import sys
from itertools import accumulate
def write_to_stdout(res):
sys.stdout.write('%s\n' % '\n'.join(res))
def read_input():
n = int(input())
worms = [int (_) for _ in input().rstrip().split()]
temp = input()
idxes = [int (_) for _ in input().rstrip().split()]
return worms, idxes
def g... | 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 void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int[] a = new int[1000000];
int n = sc.nextInt();
int m = 0;
for (int i = 0; i < n; i++)
{
int d = sc.nextInt();
for(int j = 0; j < d; j++)
{
a[m+j] = 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 BS(lis,n):
st = 0
en = len(lis) -1
while(st<en):
mid = (st+en)//2
if(lis[mid]>=n):
en = mid
else:
st = mid +1
return st
n = int(input())
lis = []
temp = input().split()
for i in temp :
lis.append(int(i))
for i in range(1,n):
lis[i]+= lis[i-1]... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
input()
q=list(map(int,input().split()))
for i in range(1,n):
a[i]+=a[i-1]
ans=""
for item in q:
ans+=f"{bisect_left(a,item)+1}\n"
print(ans) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
x = sum(a)
pileNo = [0] * x
j = 0
for i in range(x):
if(a[j] == 0):
j += 1
a[j] -= 1
pileNo[i] = j+1
for i in range(m):
print(pileNo[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_left
n=int(input())
A=[int(i) for i in input().split()]
B=[A[0]]
for i in range(1,n):
B.append(B[-1]+A[i])
t=int(input())
C=[int(i) for i in input().split()]
for i in C:
print(bisect_left(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 |
import java.util.*;
import java.lang.*;
import java.io.*;
public class kideone
{
static int d[];
public static void main (String[] args) throws java.lang.Exception
{
Scanner v=new Scanner(System.in);
int n=v.nextInt();
int ar[]=new int[n];
d=new int [n];
int ans[... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long m;
cin >> m;
long long ar[m];
for (int i = 0; i < m; i++) {
cin >> ar[i];
}
l... | 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 | __author__ = 'walkerravina'
import sys
f = sys.stdin
n = int(f.readline().strip())
A = [int(i) for i in f.readline().split()]
A[0] = (1, A[0])
for i in range(1, len(A)):
A[i] = (A[i - 1][1] + 1, A[i] + A[i - 1][1])
q = int(f.readline().strip())
Q = [int(i) for i in f.readline().split()]
for d in Q:
high = le... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | L=[]
input()
r=1
for k in input().split():
L+=[r]*int(k)
r+=1
input()
for j in input().split():
print(L[int(j)-1]) | 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 static java.lang.Math.*;
public class TestClass {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = new int[n+1];
int val[] = new int[1000000+1];
int sum=0;
int prev=0;
for(... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author George Marcus
*/
public class Main {
public static void main(String[] args) {
Inpu... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
a = map(int,raw_input().split())
l=0
d = {}
for i in range(n):
for j in range(1,a[i]+1):
d[j+l]=i+1
l+=a[i]
m = int(raw_input())
b = map(int,raw_input().split())
for i in range(m):
print d[b[i]]
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, beg, end;
vector<int> a, b;
bool d;
cin >> n;
cin >> t;
a.push_back(t);
for (int i = 0; i < n - 1; i++) {
cin >> t;
a.push_back(t + a[i]);
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
d = 0;
cin >> t;
beg ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(raw_input())
a= map(int,raw_input().split())
m=int(raw_input())
q= map(int,raw_input().split())
accu=0
for i in xrange(n):
accu+=a[i]
a[i]=accu
# for qi in q:
# lo=0
# hi=len(a)
# while lo<=hi:
# mind=int((lo+hi)/2)
#
# if qi==a[mind]:
# ... | 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
def codeforces():
_ = int(input())
a = list(map(int, input().split()))
_ = int(input())
q = (list(map(int, input().split())))
sum_p = [0 for i in range(len(a) + 1)]
sum_p[1] = a[0]
for i in range(2, len(a) + 1):
sum_p[i] += sum_p[i - 1] + a[i - 1]
result = ''
... | 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
read, read_array = raw_input, lambda: raw_input().split()
read_int, read_int_array = lambda: int(read()), lambda: [int(p) for p in read().split()]
read_float, read_float_array = lambda: float(read()), lambda: [float(p) for p in read().split()]
read()
groups = read_int_array()
bounds = []
cur = 0
for ... | 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 | # -*- coding: utf-8 -*-
"""
Created on Thu Dec 21 11:08:50 2017
@author: admin
"""
n=int(input())
p=[int(x) for x in input().split()]
m=int(input())
j=[int(x) for x in input().split()]
w=[0]*(10**6+1)
s=1
for i in range(n):
w[s:s+p[i]]=[i+1]*p[i]
s+=p[i]
for i in j:
print(w[i]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
cum =[]
nums = list(map(int, input().split()))
m = int(input())
qs = list(map(int, input().split()))
cumsum = 0
for i in range(n):
cumsum+=nums[i]
cum.append(cumsum)
for i in range(m):
left = 0
right = n-1
mid = 0
while(left < right):
mid = left+(right-left)//2
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 bisect import bisect_left
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
sums = list(accumulate(a))
ans = list()
for num in q:
ans.append(bisect_left(sums, num) + 1)
print('\n'.join(map(str, ans)))
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
public class Worms {
public static void main(String[] args) {
Scanner thing = new Scanner(System.in);
int num = thing.nextInt();
int[] sum = new int[num];
sum[0] = thing.nextInt();
for(int i = 1; num > i; i++) {
sum[i] = sum[i - 1] + thing.nextInt();
}
int numq = thing.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, i, m, temp, sum = 0, l, mid, r;
vector<int> a;
vector<int> q;
vector<int> z;
cin >> n;
for (i = 0; i < n; i++) {
cin >> temp;
a.push_back(temp);
}
cin >> m;
for (i = 0; i < m; i++) {
cin >> temp;
z.push_back(temp);
}
... | 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
from itertools import accumulate
import os
import 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
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
worms = [int(w) for w in input().split()]
m = int(input())
juicies = list(enumerate([int(j) for j in input().split()]))
l = []
s = 0
for w in worms:
s += w
l.append(s)
juicies.sort(key=lambda a:a[1])
end = 0
ans = []
for j, i in juicies:
while(True):
if i <= l[end]:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [0]
b = list(map(int,input().split()))
for i in range(len(b)):
for j in range(b[i]):
a.append(i+1)
n = int(input())
b = list(map(int,input().split()))
for i in range(len(b)):
print(a[b[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;
vector<int> a;
int main() {
a.push_back(0);
int n, q;
cin >> n;
for (int i = 1; i <= n; i++) {
int m;
cin >> m;
while (m) {
a.push_back(i);
m--;
}
}
cin >> q;
for (int i = 0; i < q; i++) {
int x;
cin >> x;
cout << a[x] <... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(input())
worm_sums = list(map(int, input().split()))
for i in range(n - 1):
worm_sums[i + 1] += worm_sums[i]
input()
for q in map(int, input().split()):
print(bisect_left(worm_sums, 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 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i - 1]
m = int(input())
b = list(map(int, input().split()))
for i in range(m):
print(bisect_left(a, b[i]) + 1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(raw_input())
a=map(int,raw_input().split())
prev=a[0]
for i in range(1,n):
a[i]+=prev
prev=a[i]
def bs(seq, t):
min = 0
max = len(seq) - 1
while True:
if max <= min:
return max
m = (min + max) // 2
if seq[m] < t:
min = m+1
elif seq[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 | n=int(input())
a=list(map(int,input().split()))
p=[(1,a[0])]
for i in range(1,n):
t=p[i-1]
p.append((t[1]+1,t[1]+a[i]))
def f(p,key,n,l,h,m):
if p[m][0]<=key<=p[m][1]:
return m,l,h
while l<=h:
m=(l+h)//2
if p[m][0]<=key<=p[m][1]:
return m,l,h
elif key>p[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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Worms {
public static void main(String[] args) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in)); //lectura de la entrada
String linea = lector.readLine(); //st... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.*;
public class CF271B {
private CF271B() throws IOException { }
private static Scanner scanner;
private static BufferedReader br;
private static StringTokenizer stringTokenizer;... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
static int [] p;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
p = new int[n];
p[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 |
def sear(a,low,high,num):
mid=(low+high)//2
if(num <= ans[mid] and num > ans[mid - 1]):
return mid
elif(num>ans[mid]):
return sear(a,mid+1,high,num)
else:
return sear(a,low,mid-1,num)
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=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.util.*;
public class Essep {
public static int[] a;
public static int[] q;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int sum = 0;
a = new int[n];
for (int i = 0; i<n; i++) {
a[i] = in.nextInt();
sum += a[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 |
get_int = lambda: map(int, input().split())
heaps_quantity = get_int()
heap_capacity = get_int()
worms_quantity = get_int()
worm_number = get_int()
a = 0
cnt = 0
h = []
for i in heap_capacity:
a += i
cnt += 1
j = a - i
while j < a:
h.append(cnt)
j += 1
for i in worm_number:
prin... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def bs(b,s,f,x):
m = 0
l = s
r = f
while(r > l):
m = (r + l)>>1
if b[m] >= x:
r = m
elif b[m] < x:
l = m + 1
return l
n = int(raw_input())
a = map(int,raw_input().split())
n1 = int(raw_input())
q = map(int,raw_input().split())
b = [0]
i = 0
for x in 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 | n = int(input())
vals = input().split()
a = [int(val) for val in vals]
m = int(input())
vals = input().split()
q = [int(val) for val in vals]
seq = []
pile = 1
for a_i in a:
seq += [pile] * a_i
pile += 1
for q_i in q:
print(seq[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 | # URL: http://codeforces.com/problemset/problem/474/B
from typing import List, Tuple
def parse_input() -> Tuple[int, List[int], int, List[int]]:
return (
int(input()),
[int(x) for x in input().split()],
int(input()),
[int(x) for x in input().split()]
)
def solve(n: int, a: 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 | def binary(a, n, ele):
l=0
h=n-1
ans=-1
while(l<=h):
m = (l+h)//2
if a[m] == ele:
return m+1
elif a[m]<ele:
l = m+1
elif a[m] > ele:
ans = m+1
h = m-1
if ans == -1:
return n
return ans
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in r... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=[int(x) for x in input().split()]
m=int(input())
q=[int(x) for x in input().split()]
import bisect
b=[a[0]]
for i in range(1,n):
b.append(a[i]+b[i-1])
for i in range(m):
print(bisect.bisect_left(b,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 | n = int(input())
p = [int(x) for x in input().split()]
m = int(input())
j = [int(x) for x in input().split()]
w = [0]*(10**6 + 1)
s = 1
for i in range(n):
w[s:s+p[i]] = [i+1] * p[i]
s += p[i]
for i in j:
print(w[i])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
import java.util.StringTokenizer;
// ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long ara[100010];
vector<long long> v;
vector<long long> v1;
long long val, sum, val1;
long long f, l, mid, mid1, res1, res2, s;
long long n, m;
void bs(long long s) {
f = 0;
l = n - 1;
while (f <= l) {
mid = (f + l) / 2;
mid1 = mid - 1;
res1 = ara[mi... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class Main {
static StreamTokenizer s = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static void main(String[] args) throws IOException {
var out = new PrintWriter(System.out);
var s = new Scanner(System.in);
int n = s.ne... | 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 search(int n, int *b, int p, int q);
int a[100005], b[100005];
int main() {
int n, sum = 0;
scanf("%d", &n);
a[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
a[i] += sum;
sum = a[i];
}
int m;
scanf("%d", &m);
for (int j = 0; j < m; j++) scanf("%d", b ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
def fin_g(a, x) :
i = bisect.bisect_left(a, x)
if i != len(a):
return i+1
else:
return len(a)
n = int(raw_input())
l = map(int, raw_input().split())
m = int(raw_input())
q = map(int, raw_input().split())
b = 0
for i in xrange(n):
b += l[i]
l[i] = b
for c in q:
print... | 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, m, res = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
res += a[i];
}
cin >> m;
int q[m];
for (int i = 0; i < m; i++) cin >> q[i];
int arr[res + 1];
int ind = 0;
for (int i = 0; i < n; i++) {
for (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 | import static java.lang.System.in;
import java.io.IOException;
public class B271 {
static byte[] buffer = new byte[8192];
static int offset = 0;
static int bufferSize = 0;
static int ceilSearch(int arr[], int low, int high, int x)
{
int mid;
if(x <= arr[low])
... | 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()))
q1 = sorted([(q[i], i) for i in range(m)])
s = 0
inx = 0
for i in q1:
while s + a[inx] < i[0]:
s += a[inx]
inx += 1
q[i[1]] = inx + 1
for i in q:
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;
vector<pair<int, int> > v;
int main() {
int n, m, item, temp, a, b, i = 0, flag = 0, start, fin, mid;
cin >> n;
int t = n;
while (n--) {
cin >> a;
if (i == 0) {
v.push_back(make_pair(1, a));
temp = a;
i++;
} else {
v.push_back(mak... | 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())
piles = input().split()
input()
juicy = input().split()
table = []
for i in range(n):
for _ in range(int(piles[i])):
table.append(i + 1)
for j in juicy:
print(table[int(j) - 1])
| PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.