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 | # n, m = map(int, input().split())
# l1 = list(map(int, input().split()))
# l2 = list(map(int, input().split()))
# l3 = [l1[0]]
#
# for i in range(1, n):
# l3.append(l3[i-1]+l1[i])
#
#
# def how_many_warriors_die(l3, n, e):
# l, r = 0, n-1
# last = n
#
# while l <= r:
# mid = (l+r)//2
# ... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i == 0)
v.push_back(a[i]);
else {
v.push_back(v[v.size() - 1] + a[i]);
}
}
int m, temp;
cin >> m;
for (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 | from bisect import bisect_left
a = int(input())
b = list(map(int,input().split()))
c = input()
d = list(map(int,input().split()))
temp = [1,b[0]]
for i in range(1,a):#Implement piles
temp.append(temp[len(temp)-1]+1)
temp.append(temp[len(temp)-1]+b[i]-1)
upperBound = []
for i in range(1,len(temp),2):#Get upperbo... | 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 cmp(double x, double y = 0, double tol = 1e-10) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
int main() {
int n;
scanf("%d", &n);
int v[n];
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
vector<pair<int, int> > seg;
seg.push_back({1, v[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 bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
piles = []
first = 0
for i in a:
piles.append(first+i)
first += i
for i in q:
print(bisect_left(piles, 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 | #!/usr/bin/env python
n = input()
piles = map(int, raw_input().split(' '))
all_worms = list()
for i in range(len(piles)):
all_worms += [i+1]*piles[i]
#print all_worms
#exit()
m = input()
jucy = map(int, raw_input().split(' '))
output = list()
for j in jucy:
output.append(all_worms[j-1])
for val in output:
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int a[100005];
pair<int, int> p[200050];
int find(int t, int n) {
int l, r, m;
l = 0, r = n;
while (1) {
m = (l + r) / 2;
if (p[m].first <= t && p[m].second >= t) {
return m + 1;
}
if (p[m].first > t)
r = m;
else
l = m;
}
}
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 | #include <bits/stdc++.h>
using namespace std;
int CUMULATIVE[300009];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool isValid(int x, int y, int n, int m) {
return x >= 0 && y >= 0 && x < n && y < m;
}
void debugMatrix(int X[][300009], int n, int m) {
int i, j;
for ((i) = (0); (i) <= (n - 1); (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 | from sys import stdin
from bisect import bisect_left as bisect
from itertools import accumulate
test_case = stdin.readlines()
worms = [int(c) for c in test_case[1].split()]
queries = [int(c) for c in test_case[3].split()]
worms_acc = list(accumulate(worms))
ans = [bisect(worms_acc, q) + 1 for q in queries]
print('\... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(raw_input())
a = map(int, raw_input().split())
m = int(raw_input())
q = map(int, raw_input().split())
cs = [0] * n
cs[0] = a[0]
for i in xrange(1, n):
cs[i] = cs[i - 1] + a[i]
for i in xrange(m):
print bisect.bisect_right(cs, q[i] - 1) + 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 | def bin(a, x):
l = -1
r = len(a)
while r > l + 1:
k = (r + l) // 2
if a[k] >= x: r = k
else: l = k
return r
n = int(input())
a = [int(i) for i in input().split()]
for i in range(1, len(a)): a[i] += a[i - 1]
m = int(input())
b = [int(i) for i in input().split()]
for i in b:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import sys
from 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 | n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
b = [0]*sum(a)
c = 0
for i in range(len(a)):
b[c:c+a[i]] = [i]*(a[i])
c += a[i]
for i in q:
print(b[i-1]+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
b=[]
for i in range(n):
b+=[i+1]*a[i]
# print(b)
for i in q:
print(b[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
lst = [int(x) for x in raw_input().split(' ')]
m = int(raw_input())
q = [int(x) for x in raw_input().split(' ')]
num = [0]
for i in range(0, len(lst)):
num.append(lst[i]+num[i])
for obj in q:
lft, rgh = 0, len(num)-1
while lft + 1 < rgh:
mid = (lft + rgh) / 2
if obj > nu... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) a[i] += a[i - 1];
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x;
cin >> x;
int val = lower_bound(a, a + n, x) - a;
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Atanas
*/
public class Main {
public static void main(String[] args) {
InputStream in... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
def search(Max,new,num):
if new[0]>num:
return 1
Min =0
Mid = int((Max+Min)/2)
while Min<=Max:
if new[Mid]==num:
return Mid+1
break
elif new[Min]==num:
return Min+1
break
elif new[Mid]<num and new[Mid+1]>num:
return Mid+2
break
elif new[Mid]<num:
Min=Mid+1
else:
Max=M... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
my_list = []
new_list = []
find_list = []
num = int(input())
my_list = list(map(int,input().split()))
a = 1
new_list.append(my_list[0])
new_list.append(my_list[0]+a+(my_list[1]-1))
for i in range(1,len(my_list)-1,1):
k = i+1
new_list.append(new_list[i]+a+(my_list[k]-1))
num = int(input())
fi... | 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 binarySearch(L, num):
i = 0
j = len(L)
mid = (i + j) // 2
out = -1
while True:
# print(i, j, mid)
if i > j or mid >= len(L):
break
elif L[mid] >= num:
out = mid
j = mid - 1
elif L[mid] < num:
i = mid + 1
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 | # Worms
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
suma = [a[0]]
i = 1
while i < n:
suma.append(suma[i-1] + a[i])
i += 1
for item in q:
high = n-1
low = 0
mid = (high+low)//2
while True:
if item > suma[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(input())
bunch = list(map(int, input().split()))
w = int(input())
worms = list(map(int, input().split()))
list = []
k = 1
for i in bunch:
list += [k] * i
k += 1
for i in worms:
print(list[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;
struct node {
int id, x;
};
bool operator<(node a, node b) {
if (a.x < b.x)
return 1;
else
return 0;
}
int main() {
int n, m, a[100009];
node b[100009];
map<int, int> ma;
cin >> n;
a[0] = 1;
n += 1;
for (int i = 1; i < n; i++) cin >> a[i];
a[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 | num_heaps = int(input())
worms_per_heap = [int(x) for x in input().split()]
worm = 1
wpdict = {}
for heap in range(1, num_heaps + 1):
for i in range(1, worms_per_heap[heap - 1] + 1):
wpdict[worm] = heap
worm += 1
num_tasty_worms = int(input())
tasty_worms = [int(x) for x in 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 = input()
a = map(int,raw_input().split())
q = input()
m = map(int,raw_input().split())
f = [0]
for i in range(n): f += [i+1]*a[i]
for x in m:
print f[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 | //474B : WORMS
/*
* Solution:
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
//Your code goes here
public class Main {
static class ProblemSolver... | 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 | # -*- coding: utf-8 -*-
"""
Created on Sun Aug 30 21:37:23 2020
@author: dehan
"""
n = input("")
a = list(map(int,input("").split()))
m = int(input(""))
q = list(map(int,input("").split()))
worm_dict = dict()
total = 0
pileId = 0
for i in range(max(q)+1):
if(i>total):
total+=a[pileId]
pileId += 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;
void pause() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
unsigned long int n, a[100005], m, q[100005];
scanf("%d", &n);
unsigned int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, p = 0;
scanf("%d", &n);
vector<int> v;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
v.push_back(p + a);
p += a;
}
vector<int>::iterator it;
int q, x;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &x);
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class marmot {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n+1];
int[] prefix = new int[n+1];
for(int i=1;i<n+1;i++)
{
arr[i] = in.nextInt();
}
prefix[1] = arr[1]... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i - 1]
for x in q:
left = 0
right = n
while left < right:
mid = (left + right) // 2
if x > a[mid]:
left = mid + 1
elif x <= a[mid] and (mid == 0 or x > a[... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n,a = input(),map(int, raw_input().split())
m,q = input(),map(int, raw_input().split())
dp = []
for i in xrange(n):
dp += [i+1]*a[i]
for x in q:
print dp[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 os
import sys
from collections import Counter
from io import BytesIO, IOBase
import bisect as bi
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())
a = list(map(int, input().split(' ')))
m = int(input())
q = list(map(int, input().split(' ')))
for i in range(1, n):
a[i] = a[i] + a[i - 1]
l = 0
k = [k for k in range(1000000)]
for i in range(n):
for j in range(l, a[i]):
k[j] = i + 1
l = a[i]
for i in range(m):
print(k[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 | import math
n=int(input())
a=[int(x) for x in input().split()]
m=int(input())
q=[int(x) for x in input().split()]
label=[0]
for i in a:
label.append(label[-1]+i)
for i in q:
low=0
high=n
while True:
mid=math.floor((low+high)/2)
if i>label[mid-1] and i<=label[mid]:
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 | import java.io.BufferedReader;
import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
/**
* Author: Luis Manuel Díaz Barón
* Problem:
* Online Judge: COJ
* Idea:
*
*/
public class Main {
static MyScanner sc;
static MyWriter mw;
static String filePath=... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
label=[]
for i in range(len(a)):
if i ==0:
x=a[0]
label.append(x)
else:
x=(label[i-1]+a[i])
label.append(x)
for i in range(len(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.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static ... | 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 *
input()
a = [int(x) for x in input().split()]
input()
q = [int(x) for x in input().split()]
for i in range(1, len(a)):
a[i] += a[i - 1]
for x in q:
print(bisect_left(a, x) + 1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import static java.lang.Math.*;
import java.util.Arrays;
public class Maybethistimeyouwillcomplie {
static PrintWriter out = new PrintWriter(System.out);
static Scan in = new Scan();
static int bs(int[] a1, int[] a2, int L, int R, int key){
while (L <= R){
... | 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
nw=int(input())
w=input().split(' ')
wa=[int(w[0])]
for i in range(1,nw):
wa.append(int(w[i])+int(wa[i-1]))
np=int(input())
p=input().split(' ')
for i in range(np):
print(bisect.bisect_left(wa,int(p[i]))+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int arr2[1000005] = {0};
int main() {
int arr1[100005];
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr1[i];
int x = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < arr1[i]; j++) {
arr2[x] = i + 1;
x++;
}
}
int m, y;
cin >>... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int A[1001000];
int main() {
int n;
cin >> n;
int sum = 0;
int tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
for (int j = sum + 1; j <= sum + tmp; j++) A[j] = i + 1;
sum += tmp;
}
int m, q;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> q;... | 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()
q = map(int, raw_input().split())
res = []
for i in range(n):
res += [i + 1] * a[i]
for i in q:
print 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 | from bisect import bisect_left
from itertools import accumulate
def find_ge(a, x):
i = bisect_left(a, x)
if i != len(a):
return i
n = input()
l1=list(accumulate(list(map(int,input().split()))))
q=input()
l2 = list(map(int, input().split()))
for i in l2:
print(find_ge(l1,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()))
input()
queries = list(map(int, input().split()))
ans = []
for i in range(n):
ans += [i]*a[i]
for q in queries:
print(ans[q-1]+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Arrays;
import java.util.Collections;
import java.util.InputMismatchException;
public class MapArray {
public static void mai... | 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
f = sys.stdin.readline
n = int(f().strip())
arr = [int(v) for v in f().strip().split()]
pre = [0]*n
pre[0] = arr[0]
for i in range(1, n):
pre[i] += arr[i]+pre[i-1]
from bisect import bisect_left
m = int(f().strip())
q = [int(v) for v in f().strip().split()]
for v in q:
i = bisect_left(pre, v)
pri... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # -*- coding: utf-8 -*-
"""
Created on Tue Nov 6 16:31:46 2018
@author: Quaint Sun
"""
n=int(input())
ai=list(map(int,input().split()))
for i in range(1,n):
ai[i]=ai[i]+ai[i-1]
pile=[1]*(ai[-1])
num=2
for i in range(1,n):
for j in range(ai[i-1],ai[i]):
pile[j]=num
num=num+1
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 | def bins(a, key ,n):
l=0; r=n-1
while l<=r:
mid = (l+r)//2
if a[mid]<key: l = mid+1
else:
if mid==0 or a[mid-1]<key:
return mid+1
r = mid
n = int(input())
a = list(map(int, input().split()))
dp = [a[0]]
for i in range(1, n):dp.append(dp[-1]+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 | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.lang.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int []... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long binSrc(long long arr[], long long n, long long item) {
long long mid, lo, hi;
lo = 0;
hi = n - 1;
while (lo <= hi) {
mid = lo + ((hi - lo) / 2);
if (arr[mid] ==... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 1;
int n, x, q;
int a[M];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
a[i] += x + a[i - 1];
}
scanf("%d", &q);
while (q--) {
scanf("%d", &x);
printf("%d\n", lower_bound(a, a + n, x) - a);
}
}
| CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int a, b = 0, c, z, y, l, r, t;
int main() {
cin >> a;
int A[a];
for (z = 0; z < a; z++) {
cin >> b;
if (z > 0) {
A[z] = A[z - 1] + b;
} else {
A[z] = b;
}
}
cin >> a;
int B[a];
int C[a];
for (z = 0; z < a; z++) {
cin >> B[z];... | 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())
l = list(map(int,input().split()))
m = int(input())
a = (list(map(int,input().split())))
dic = {i:0 for i in a}
tp = a
a = sorted(a)
for i in range(1,n):
l[i]+=l[i-1]
i,j = 0,0
while i<m:
if a[i]<=l[j]:
dic[a[i]]=j+1
i+=1
continue
j+=1
for val in tp:
print(dic[va... | 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 maxn = 1e5 + 10;
int a[maxn], l[maxn], r[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[i] = a[i - 1] + x;
l[i] = a[i - 1] + 1;
r[i] = a[i];
}
r[n + 1] = 1e9;
l[n + 1] = 1e9;
i... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(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 | from sys import stdin, stdout
from collections import defaultdict
import heapq
import bisect
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split())
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readli... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int a[100005], s[1000005];
int main() {
int n, i, j, m, q;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
int cou = 1;
for (i = 0; i < n; i++) {
for (j = 0; j < a[i]; j++) {
s[cou++] = i + 1;
}
}
cin >> m;
for (i = 0; i < m; i++) {
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #!/usr/bin/python
import sys
def read_obj(cls):
return cls(sys.stdin.readline().strip())
def read_obj_list(cls):
return map(cls, sys.stdin.readline().strip().split())
def solve():
piles = read_obj(int)
worms = read_obj_list(int)
juicy_number = read_obj(int)
juicy = read_obj_list(int)
jui... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(input())
a = [int(i) for i in input().split()]
pref = [0] * (n + 1)
for i in range(1, n + 1):
pref[i] = pref[i - 1] + a[i - 1]
m = int(input())
b = [int(i) for i in input().split()]
for i in range(m):
now = b[i]
index = bisect.bisect_left(pref, now)
print(index)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
import io
import os
import bisect
total = 0
failed = 0
def debug(a):
print(a, file=sys.stderr)
def run(test,res):
x = io.StringIO()
with io.StringIO(test) as sys.stdin:
with x as sys.stdout:
work()
z = x.getvalue().strip()
sys.stdout = sys.__stdout__
print... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [None for i in range(1000000)]
j = 0
h = 1
for i in list(map(int, input().split())):
for _ in range(i):
a[j] = h
j+=1
h+=1
input()
for i in list(map(int, input().split())):
print(a[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class EjerH3{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, m, cont;
n=sc.nextInt();
int[] arr = new int[n+1];
cont=0;
arr[0]=0;
int res=0;
for (int i = 1; i < n+1; i++) {
cont=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 | #include <bits/stdc++.h>
using namespace std;
int A[100005];
int bsearch(int q, int l, int r) {
if (l == r - 1) {
return l;
}
int mid = (l + r) / 2;
if (A[mid - 1] < q && q <= A[mid]) {
return mid;
} else if (q <= A[mid - 1]) {
return bsearch(q, l, mid);
} else {
return bsearch(q, mid, r);
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
first = input()
n = (int)(first)
second = input().split()
piles = [(int)(x) for x in second]
first = input()
m = (int)(first)
second = input().split()
juicy = [(int)(x) for x in second]
for i in range(1,n):
piles[i] = piles[i]+piles[i-1]
for i in range(m):
beg = 0
last = n-1
while(beg<=last):
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int p[100010];
p[0] = 0;
for (i = 0; i < n; i++) {
int b;
cin >> b;
p[i + 1] = p[i] + b;
}
int m;
cin >> m;
for (i = 0; i < m; i++) {
int worm;
cin >> worm;
int ans = lower_bound(p, p + n, worm) - p;... | 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 busca_binaria(lista, busca):
inicio, fim = 0, len(lista)-1
while inicio <= fim:
meio = (inicio + fim)/2
if busca == lista[meio]:
return meio + 1
else:
if lista[meio] < busca:
inicio = meio + 1
else:
fim = meio - 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;
long long ara[100010];
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[mid];
res2 = 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 | n = raw_input()
numberOfWorms = map(int, raw_input().split())
m = input()
juicyWorms = map(int, raw_input().split())
for i in range(1,len(numberOfWorms)):
numberOfWorms[i] += numberOfWorms[i-1]
for i in juicyWorms:
start = 0
end = len(numberOfWorms) - 1
while start <= end:
mid = (end - start) / 2 + start
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 | R = lambda: map(int, raw_input().split())
n, a, m, q = input(), R(), input(), R()
for i in range(1,n):
a[i] += a[i-1]
for x in q:
lo, hi = 0, n
while lo < hi:
mid = (lo + hi) / 2
if a[mid] < x:
lo = mid + 1
elif a[mid] >= x:
hi = mid
print lo + 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.*;
public class bit8 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
a[0] = in.nextInt();
for(int i=1;i<... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int binary(long long int s[], int t, int m) {
int l = 0, h = m - 1;
while (l <= h) {
int mid = (l + h) / 2;
if (s[mid] == t)
return mid;
else if (l == h)
return l;
else if (t > s[mid])
l = mid + 1;
else if (t < s[mid])
h = mid... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | L= []
input()
r = 1
for k in input().split():
L += [r] * int(k)
r = 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 sys
def solve():
n , = read()
mem = read()
count = sum(mem)
mem2 = [0]*count
index = 0;
for i in range(n):
temp = mem[i];
for j in range(temp):
mem2[index] = i
index+=1
m , = read()
second = read()
for i in range(m):
temp = seco... | 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 bs {
public static void main(String[] args){
// int[] arr={1,2,3,4};
Scanner scn=new Scanner(System.in);
// long t=scn.nextLong();
// while(t-->0){
int n=scn.nextInt();
int[] a=new int[n];
for(int i=0;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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m, j, cnt = 0, ans, x, sum = 0;
cin >> n;
int a[n], c[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
c[i] = sum;
}
cin >> m;
int b[m];
for (i = 0; i < m; i++) cin >> b[i];
for (j = 0; j < m; j++) {
cout << 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 |
import java.io.*;
import java.util.*;
public class Worms
{
static StringTokenizer st;
static BufferedReader in;
static PrintWriter out;
private static int nextInt() throws IOException
{
return Integer.parseInt(next());
}
private static long nextLong() throws IOException
{
return Long.par... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x;
vector<int> sum(n);
for (int i = 0; i < n; i++) {
cin >> x;
if (i == 0)
sum[i] = x;
else {
sum[i] = x + sum[i - 1];
}
}
int m;
cin >> m;
vector<int> j(m);
for (int 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long int M, k, Q, sum = 0, a = 1, W;
vector<int> x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &W);
for (int j = 0; j < W; j++) {
x.push_back(i);
}
}
scanf("%lld", &M);
for (k = 1; k <= M; k++) {
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(input())
lst = [i for i in map(int, input().split())]
for i in range(1, len(lst)):
lst[i] += lst[i-1]
_ = input()
for item in map(int, input().split()):
print(bisect.bisect_left(lst, item) + 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
int(input())
A = [0]
for i in map(int, input().split()):
A.append(A[-1]+i)
int(input())
for i in map(int, input().split()):
print(bisect.bisect_left(A, 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.util.Arrays;
import java.util.Scanner;
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int[] a=new int[n];
a[0]=in.nextInt();
for(int i=1;i<n;i++){
a[i]=in.nextInt()+a[i-1];
}
int m=in.nextIn... | 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
def binarySearch(arr, val):
l = 0
r = len(arr)
while(l < r - 1):
m = int((l + r) / 2)
if(arr[m] < val):
l = m
else:
r = m
return r
n = int(sys.stdin.readline())
z = [int(x) for x in (sys.stdin.readline()).split()]
an = []
for i in ... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import 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.Scanner;
import java.util.StringTokenizer;
public class aaa {
static StringTokenizer 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 | n = int(input())
a = [0]
a.extend(list(map(int,input().split())))
m = int(input())
q = list(map(int,input().split()))
t = a[0]
temp = [t]
for i in range(1,len(a)):
t+=a[i]
temp.append(t)
t = [0]*(sum(a)+1)
x = 1
for i in range(1,n+1):
for j in range(temp[i-1],temp[i]+1):
t[j]=x
x+=1
for item in q:
print(t[ite... | 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 | """
// Author : snape_here - Susanta Mukherjee
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int m;
cin >> m;
for (int i = 1; i < n; i++) {
v[i] += v[i - 1];
}
for (int i = 1; i <= m; i++) {
int target;
cin >> target;
int start = 0;
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
int A[n];
vector<int> V1;
for (int i = 0; i < n; i++) {
cin >> A[i];
for (int j = 0; j < A[i]; j++) V1.push_back(i + 1);
}
cin >> m;
for (int i = 0; i < m; i++) {
int w;
cin >> w;
cout << V1[w - 1] << endl... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;
public class TestClass {
private static InputStream stream;
private static byte[] buf = new byte[1024];
private static int curChar;
private static int numChars;
private static SpaceCharFilter filter;
private static Pri... | 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.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Ruff4
{
static PrintWriter out =new PrintWriter(System.out);
public static void main(String[] args)
{
Scanner vicky=new Scanner(System.in);
int n=vicky.nextInt();
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | N = int(input())
L = list(map(int,input().split()))
J = int(input())
L1 = list(map(int,input().split()))
NewL = [0]*sum(L)
temp = 0
for i in range(N):
for j in range(L[i]):
NewL[temp+j]=i+1
temp+=L[i]
for i in L1:
print(NewL[i-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.lang.Math;
import java.io.*;
public class Worm
{
public static void main(String args[]) throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n;
cin >> n;
unordered_map<long long int, long long int> pos;
long long int prev, now;
cin >> now;
for (long long int i = 1; i <= now; ++i) pos[i] = 1;
for (long... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | N, a, M, q = int(raw_input()), map(int, raw_input().split()), int(raw_input()), map(int, raw_input().split())
for i in range(1, N):
a[i] += a[i - 1]
for i in range(M):
lo, hi = 0, N
while(lo < hi):
m = (lo + hi) / 2
if(a[m] < q[i]):
lo = m + 1
else:
hi = m
print lo + 1
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
arrSize=int(input())
arr=list(map(int,input().split()))
sum=0
prefix_array=[]
for i in arr:
sum+=i
prefix_array.append(sum)
quries=int(input())
que=list(map(int,input().split()))
for i in que:
print(bisect.bisect_right(prefix_array,i-1)+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int dp[1000000];
int main() {
int n;
cin >> n;
int arr[n];
int sum = 0;
int count = 1;
int k;
for (int i = 0; i < n; i++) cin >> k, sum += k, dp[sum] = count++;
count = 1;
for (int i = 1; i <= sum; i++) {
if (dp[i]) {
count++;
} else
dp... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # def bsearch(arr, target):
# lo = 0
# hi = len(arr) - 1
# while lo <= hi:
# mi = (lo + hi) // 2
# if arr[mi] == target:
# return mi
# elif arr[mi] > target:
# hi = mi - 1
# else:
# lo = mi + 1
# return (lo + hi) // 2 + 1
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a, s = 0;
vector<int> result;
for (int i = 1; i <= n; i++) {
cin >> a;
s += a;
result.push_back(s);
}
int m, b;
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> b;
int answer = lower_bound(result.begin()... | 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 binarySearch(vector<long long> &A, int i, int j, long long n) {
int m, result = -1;
while (i <= j) {
m = (i + j) >> 1;
if (A[m] == n) {
result = m;
break;
} else {
if (n > A[m])
i = m + 1;
else
j = m - 1;
... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.