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=input()
n=int(n)
pile=[]
pile=input().rstrip().split(' ')
pile[0]=int(pile[0])
for i in range(1,n):
pile[i]=int(pile[i-1])+int(pile[i])
m=input()
labels=[]
labels=input().rstrip().split(' ')
def Binary_search(x):
start=0
end=n-1
while (start <= end) :
mid =int((start+end)/2)
if (x>pile... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class worms {
public static int binarySearch( int[] a , int x) {
int m ;
int l = 0;
int r =a.len... | 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.math.BigInteger;
import java.lang.String;
import java.util.*;
public class Main {
static int binarySearch(int a[], int low, int high, int key){
while (low < high) {
int mid = (low + high) / 2;
if (key < a[0])
low = 1;
if (key >= a[mid])
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
void fn(long long int *arr, int n, long long int val) {
int st = 0, en = n - 1;
int ans;
while (st <= en) {
int mid = (st + en) >> 1;
if (arr[mid] == val) {
ans = mid + 1;
break;
} else if (arr[mid] > val) {
ans = mid + 1;
en = 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;
int arr[100005], mat[100005];
int main() {
int n, m, i, temp, j, z;
scanf("%d", &n);
mat[0] = 0;
for (i = 1, j = 1; i <= n; i++, j++) {
scanf("%d", &arr[i]);
mat[j] = mat[j - 1] + arr[i];
}
sort(arr + 1, arr + 1 + n);
scanf("%d", &m);
while (m--) {
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | 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 j in q:
l=0
u=n
p=10**7
while l<=u:
mid=(l+u)//2
if a[mid]>=j:
p=min(mid,p)
u=mid-1
else:
l=mid+1
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 | n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i - 1]
#Это была подготовка
k = int(input())
items = list(map(int, input().split()))
for x in items:
l = 0
r = n
while l < r:
m = l + (r - l) // 2
if a[m] >= x:
r = m
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 sys
from collections import Counter
input = sys.stdin
output = sys.stdout
# input = open('input.txt')
def read_int():
return [int(x) for x in input.readline().rstrip().split()]
[n] = read_int()
a = read_int()
[m] = read_int()
q = read_int()
s = [0]
for _a in a:
s.append(s[-1] + _a)
answers = []
f... | 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::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, k, l, r, m;
cin >> n;
long long a[n + 7];
for (long long i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1) a[i] = a[i] + a[i - 1];
}
cin >> k;
long long b[k + 7];
for (... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # n = int(input())
# a = [1]
# for i in range(n):
# print(*a)
# a = [1] + [a[j] + a[j + 1] for j in range(i)] + [1]
#a = 1
#n = int(input())
#for i in range(2, n):
# if n % i == 0:
# a = 0
# break
#if a == 0:
# print("I am way to dumb to get an answer correctly")
# print("NO")
#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 | from bisect import bisect_left
def bs(a, x, lo=0, hi=None): # can't use a to specify default for hi
hi = hi if hi is not None else len(a) # hi defaults to len(a)
pos = bisect_left(a,x,lo,hi) # find insertion position
return (pos if pos != hi and a[pos] >= x else -1) # don't walk off the end
... | 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>
int prefix[((int)1e6 + 10)], arr[((int)1e6 + 10)];
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
prefix[0] = arr[0];
for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + 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 | n=int(input())
a=[int(p) for p in input().split()]
m=int(input())
l=[int(q) for q in input().split()]
d=[]
k=0
for i in range(n):
d+=[i+1]*a[i]
for i in range(m):
print(d[l[i]-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import *
n = int(raw_input())
a = [int(i) for i in raw_input().split()]
m = int(raw_input())
b = [int(i) for i in raw_input().split()]
c = [0]*n
c[0] = a[0]
for i in range(1, n):
c[i] = c[i-1] + a[i]
for i in b:
print bisect(c, 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 | n = int(input())
num = list(map(int, input().split()))
m = int(input())
ju = list(map(int, input().split()))
li = [0] * (10 ** 6 + 1)
s = 1
for i in range(n):
li[s: s + num[i]] = [i + 1] * num[i]
s += num[i]
for i in range(len(ju)):
print(li[ju[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 e in q:
print(bisect_left(sums,e)+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 int myXOR(unsigned long long int x, unsigned long long int y) {
return (x | y) & (~x | ~y);
}
long long int powerLL(long long int x, long long int n) {
long long int result = 1;
while (n) {
if (n & 1) result = result * x % 1000000007;
n = n / 2;
... | 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() {
long n, m, c[1000001]{0}, x, p = 1;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x;
for (int j = p; j <= p + x - 1; ++j) c[j] = i;
p += x;
}
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> x;
cout << c[x] << endl;
}
return ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Worms implements Closeable {
private InputReader in = 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 | import java.util.*;
import java.io.*;
import java.math.*;
public class cf{
public static void main(String args[]) throws Exception{
Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n=sc.nextInt();
ArrayList<Integer> ans=new ArrayList<>();
long[] a=new long[n];
a[0]=sc.nextLong(... | 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 worms[1000010];
int piles[100010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", piles + i);
int now = 1;
for (int i = 0; i < n; i++) {
fill(worms + now, worms + now + piles[i], i + 1);
now += piles[i];
}
int m;
sca... | 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.Scanner;
public class P4 {
private static int upperBound(int[] a, int low, int high, int element){
while(low < high){
int middle = low + (high - low)/2;
if(a[middle] >= element)
high = middle;
else
low = middle + 1;
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, f;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (i - 1 >= 0) {
arr[i] += arr[i - 1];
}
}
int pi = arr[n - 1];
int p[pi], c = 0;
for (int i = 0; i <= pi; i++) {
p[i] = c;
if (i == arr[c... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [int(x) for x in input().split()]
grupos = []
ng = 1
for i in a:
for j in range(i):
grupos.append(ng)
ng += 1
m = int(input())
b = [int(x) for x in input().split()]
for k in b:
print(grupos[k - 1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | 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))
for q in queries:
idx = bisect(worms_acc, q)
print... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
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 | #include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int main() {
cin >> n;
v.push_back(0);
for (int i = 0; i < n; ++i) {
int num;
cin >> num;
v.push_back(v[(int)v.size() - 1] + num);
}
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int num;
cin >> num;
cout << lower... | 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(' ')
m = input()
asks = input().split(' ')
guia = 0
ant = 0
for pile in piles:
piles[guia] = ant + int(piles[guia])
ant = piles[guia]
guia += 1
for ask in asks:
curAsk = int(ask)
piv1 = 0
piv2 = n-1
while(piv1 + 1 < piv2):
midPoint = (piv1+piv... | 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
m=int(input())
a=[int(x) for x in input().split()]
for i in range(m-1):
a[i+1]+=a[i]
n=int(input())
b=[int(x) for x in input().split()]
for i in b:
m=bisect.bisect_left(a,i)+1
print(m)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
N=int(input())
lst=list(map(int,input().split()))
m=int(input())
lst1=list(map(int,input().split()))
ans=[]
x=[]
x.append(lst[0])
for i in range(1,len(lst)):
x.append(lst[i]+x[i-1])
for j in range(len(lst1)):
count=0
count=bisect.bisect_left(x, lst1[j])
print(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;
using ll = long long;
void solution() {
int n;
cin >> n;
int *a = new int[1000001]{};
int last = 0;
for (int i = 1; i <= n; ++i) {
int w;
cin >> w;
int beg = last + 1, end = last + w;
for (int j = beg; j <= end; ++j) a[j] = i;
last += w;
}
... | 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() {
long long n, m;
cin >> n;
long long *arr = new long long[n];
for (long long i = 0; i < n; ++i) {
cin >> arr[i];
}
cin >> m;
int *arr2 = new int[m];
for (int i = 1; i < n; ++i) {
arr[i] = arr[i] + arr[i - 1];
}
for (long long i = 0; 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 | //package Atcoder;
import java.io.*;
import java.util.*;
public class wtf {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String inp[]=br.readLine().split(" ");... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #comment to pass again, again
n = int(raw_input())
worms = [int(x) for x in raw_input().split()]
m = int(raw_input())
juicy = [int(y) for y in raw_input().split()]
somas_parciais = [worms[0]]
soma=worms[0]
for i in worms[1:]:
soma+=i
somas_parciais.append(soma)
def bsearch(k,n):
left = 0
right = n
while(lef... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
a = [int(x) for x in raw_input().split()]
m = int(raw_input())
q = [int(x) for x in raw_input().split()]
for i in range(n - 1):
a[i + 1] += a[i]
b = [0] + a
def bi(l , x):
first = 0
last = len(l) - 1
found = False
while first <= last and (not found):
mid = (first + la... | 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>
int main() {
int n;
scanf("%d", &n);
int a[n], i;
for (i = 0; i < n; i++) scanf("%d", a + i);
int m;
scanf("%d", &m);
int num[m];
for (i = 0; i < m; i++) scanf("%d", num + i);
for (i = 1; i < n; i++) a[i] += a[i - 1];
for (i = 0; i < m; i++) {
int mid, lo = 0, hi = n - 1... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.util.Scanner;
public class Worms {
public static void main(String asd[])throws Exception
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int a[]=new int[n];
int sum=0;
for(int i=0;i<n;i++)
sum+=a[i]=in.nextInt();
int b[]=new int[... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
a=list(map(int,input().split()))
dp=[a[0]]
for i in range(1,len(a)):
dp.append(dp[-1]+a[i])
k=int(input())
q=list(map(int,input().split()))
for i in q:
print(bisect.bisect_left(dp,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())
w = [int(i) for i in raw_input().split(" ")]
m = int(raw_input())
W = [int(i) for i in raw_input().split(" ")]
f = 1
s = w[0]
l = w[0]
P = [[f,s]]
for i in range(1,len(w)):
f = f+l
s = s+w[i]
P.append([f,s])
l = w[i]
t = 0
for i in w:
t += i
D = {}
j = 1
for i in range(1,t+1):
if i > P[j-1... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))
for i in range(1,n):
A[i] = A[i] + A[i - 1]
for i in B:
l = -1
r = n - 1
while l + 1 < r:
m1 = (l + r) // 2
if A[m1] >= i:
r = m1
else:
l = m1
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 | /**
* Created by Dima on 06.10.2014.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TaskB271 {
private static BufferedReader reader;
private static PrintWriter writer;
private stat... | 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 fun(int, int, int);
long long int ary[100001];
int main() {
int number;
cin >> number;
ary[0] = 1;
for (int i = 1; i <= number; i++) {
int a;
cin >> a;
ary[i] = ary[i - 1] + a;
}
int p;
cin >> p;
for (int i = 0; i < p; i++) {
int n;
c... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
A=[]
for i in range(n):
for j in range(a[i]):
A.append(i+1)
for i in q:
x=A[i-1]
print(x)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #!/usr/bin/env python3
import bisect
n = int(input())
piles = list(map(int, input().split()))
m = int(input())
juicy = list(map(int, input().split()))
for i in range(1, n):
piles[i] = piles[i-1] + piles[i]
for j in juicy:
idx = bisect.bisect_left(piles, j)
print(idx + 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())
l1=list(map(int,input().split()))
nw=int(input())
l2=list(map(int,input().split()))
for i in range(1,n):
l1[i]+=l1[i-1]
for i in range(nw):
beg=0
end=n-1
while beg<=end:
mid=(beg+end)//2
if l2[i]<=l1[mid]:
if mid==0:
print(mid+1)
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | L=[]
r=1
input()
for k in input().split():
L+=[r]*int(k)
r+=1
input()
for j in input().split():
print(L[int(j)-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
arr = list(map(int, input().split()))
m = int(input())
query = list(map(int, input().split()))
for i in range(1,len(arr)):
arr[i] += arr[i-1]
def bs(q):
l,r = 0, len(arr)
while(l<r):
mid = (l+r)//2
if arr[mid] == q:
return mid+1
elif arr[mid] < 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 | #include <bits/stdc++.h>
using namespace std;
int n, x, q;
int a[100100];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x;
a[i] = a[i - 1] + x;
}
cin >> q;
while (q--) {
cin >> x;
cout << lower_bound(a + 1, a + 1 + n, x) - a << 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 | 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
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = 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 | import java.util.Scanner;
/**
* https://codeforces.com/contest/474/problem/B
*/
public class Problem474B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long[] range = new long[1000001];
int pile = 1;
int index = 1;
long worms;
int ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import math
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = map(int, input().split())
return n,m
def dva():
n, m = 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 | 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())
q = list(map(int,input().split()))
for i in q:
print(bisect_left(a,i)+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int num[1000000 + 10];
int main() {
int n;
cin >> n;
int arr[n + 5];
for (int i = 1; i <= n; i++) cin >> arr[i];
int k = 1;
for (int i = 1; i <= n; i++) {
int x = arr[i];
for (int j = k; j < k + x; j++) num[j] = i;
k = k + x;
}
int m;
cin >> m;... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import *
n = int(input())
l = [*map(int,input().split())]
arr = [l[0]]
for i in range(1,n):
arr.append(arr[-1]+l[i])
#print(arr)
m = int(input())
for i in input().split():
x = int(i)
print(bisect_left(arr,x)+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[100010];
a[0] = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[i + 1] = a[i] + x;
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int t, ans;
cin >> t;
ans = lower_bound(a, a + n, t) - 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.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException {
Reader.init(System.in);
int n = Reader.nextInt();
int c[] = new int[1000002];
int x=0;
for (int i = 0; i < n; i++) {
int s=Reader.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[100001];
int main() {
int n, m, x;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++) a[i] += a[i - 1];
cin >> m;
while (m--) {
cin >> x;
cout << 1 + (lower_bound(a, a + n, x) - a) << 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 bisect import *
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1): a[i + 1] += a[i]
input()
for i in map(int, input().split()): print(bisect_left(a, i) + 1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Scanner;
/**
* Class: <br />
* Date: 2014/10/06 23:30<br />
* Description:<br />
*
* @author sjtudesigner
*/
public class ProblemB {
private static int binary_search(int[] list, int num)
{
int left = 0;
int right = list.length;
while (left < right)
{
... | 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 run():
piles=input()
a=map(int,raw_input().split())
query=input()
q=map(int,raw_input().split())
bigs=sum(a)
base=1
pile=1
maps={}
for each in a:
for i in xrange(base,base+each):
maps[i]=pile
base+=each
pile+=1
#print maps
for each in q... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # http://codeforces.com/problemset/problem/474/B
n = int(input())
a = [int(i) for i in input().split()]
t = list()
p = 1
for i in a:
t.extend([p]*i)
p += 1
m = int(input())
q = [int(i) for i in input().split()]
for i in q:
print(t[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 | input()
line=list(map(int,input().split()))
input()
worm=list(map(int,input().split()))
label=[0]*(10**6+1)
number=line[0]
count=1
for i in range(1,sum(line)+1):
if i<=number:
label[i]=count
else:
count+=1
number+=line[count-1]
label[i]=count
for i in worm:
print(label[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 bisect
n = int(input())
tmp = input().split()
a = list()
order = list()
s = 1
for i in range(1, n+1):
s = s + int(tmp[i-1])
order.append(i)
a.append(s)
m = int(input())
nums = input().split()
for i in nums:
print(order[bisect.bisect(a, int(i))])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [0]*1000000
pos = 0
q = [int(s) for s in input().split()]
for i in range(n):
l=q[i]
for j in range (pos,l+pos):
a[j] = i+1
pos=l+pos
w = int(input())
ww = [int(s) for s in input().split()]
for i in range (w):
print(a[ww[i]-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100009] = {0};
cin >> n >> a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
int m;
cin >> m;
while (m--) {
int k;
cin >> k;
int t = (int)(lower_bound(a, a + n, k) - a + 1);
cout << t << 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 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solution() {
int n;
cin >> n;
int *a = new int[1000001]{};
int last = 0;
for (int i = 1; i <= n; ++i) {
int w;
cin >> w;
int beg = last + 1, end = last + w;
for (int j = beg; j <= end; ++j) a[j] = i;
last += w;
}
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from itertools import accumulate
import bisect
n = int(input())
piles = [int(i) for i in input().split()]
piles = list(accumulate(piles))
m = int(input())
worms = [int(i) for i in input().split()]
for worm in worms:
print(bisect.bisect_left(piles,worm)+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
from bisect import bisect_left
n = int(sys.stdin.readline())
a = map(int, sys.stdin.readline().split())
m = int(sys.stdin.readline())
q = map(int, sys.stdin.readline().split())
def bin_find(arr, x):
position_begin = 0
position_end = len(arr) - 1
while position_begin != position_end:
po... | 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 | bunch_count = int(input())
bounds_input = [int(i) for i in input().split()]
juicy_worms_count = int(input())
juicy_worms_number = [int(i) for i in input().split()]
worms_index = []
bunch_number = 1
for i in bounds_input:
for j in range(i):
worms_index.append(bunch_number)
bunch_number += 1
for worm in j... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n;
vector<long long> a, q, pp;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
a.push_back(x);
}
cin >> m;
for (long long i = 0; i < m; i++) {
long long x;
cin >> x;
q.push_back(x);
}
v... | 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 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/23 10:18
"""
N = int(input())
A = [int(x) for x in input().split()]
M = int(input())
Q = [int(x) for x in input().split()]
left = [0] * (N + 1)... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ProblemB {
BufferedReader rd;
private ProblemB() throws IOException {
rd = new BufferedReader(new InputStreamReader(System.in));
rd.readLine();
int[] a = intarr();
int n = ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin
def binary(num,n):
global dor
lo,hi=0,n
while lo<hi:
mid=lo+(hi-lo)//2
if dor[mid]>=num:
hi=mid
else:
lo=mid+1
return lo
def main():
global dor
n=int(stdin.readline().strip())
dor=[int(x) f... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
N=input()
a=map(int,raw_input().split())
M=input()
q=map(int,raw_input().split())
a2=[0 for i in xrange(N)]
a2[0]=a[0]
flag=[0 for i in xrange(N)]
for i in range(1,N):
a2[i]=a[i]+a2[i-1]
#print a2
#print q
for x in q:
ans=bisect.bisect_left(a2,x)
print str(ans+1)
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
import math
a=int(input())
b=list(map(int,input().split()))
c=int(input())
d=list(map(int,input().split()))
e=[]
f=0
for i in b:
#print(f,i)
e.append(f+i)
f=i+f
g=[0]*(e[-1]+1)
h=0
for i in range(a):
for j in range(h,e[i]+1):
g[j]=i+1
h=e[i]+1
for k in d:
print(g[k]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, m;
int a[N];
int main() {
std::ios::sync_with_stdio(0);
;
cin >> n;
int cnt = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
while (x--) {
a[++cnt] = i;
}
}
cin >> m;
while (m--) {
int x;
cin >>... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin
from bisect import bisect_left
stdin.readline()
x, l = 0, []
for y in map(int, stdin.readline().split()):
x += y
l.append(x)
stdin.readline()
for y in map(int, stdin.readline().split()):
print(bisect_left(l, y) + 1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, q;
int p[100005];
int search(int x) {
int in;
int l, r, mid;
l = 1, r = n;
while (l < r) {
mid = l + r;
mid >>= 1;
if (p[mid] >= x)
r = mid;
else
l = mid + 1;
}
return l;
}
int main() {
ios_base::sync_with_stdio(false);
cin... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(input())
worms_per_pile = [0] + list(map(int, input().strip().split()))
m = int(input())
queries = list(map(int, input().strip().split()))
accumulator = []
partial_sum = 0
for pile in worms_per_pile:
partial_sum += pile
accumulator.append(partial_sum)
for query in queries:
print(bisect.bis... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # your code goes here
def bsearch_left(arr, target):
lo = 0
hi = len(arr) - 1
ans = -1
while lo <= hi:
mid = (lo+hi)//2
if arr[mid] >= target:
ans = mid
hi = mid-1
else:
lo = mid + 1
return ans
n = int(input())
a = list(map(int, input().split(" ")))
ps = []
for i in range(len(a)):
if i == 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;
int main() {
int arr[100000], n, m, q;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 1; i < n; i++) arr[i] += arr[i - 1];
cin >> m;
for (int i = 0; i < m; i++) {
cin >> q;
int low = lower_bound(arr, arr + n, q) - arr;
cout << low ... | 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;
void printList(vector<long long> v) {
for (long long i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long n;
cin >> n;
vector<long long> arr(n);
for (long lon... | 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
import bisect
n=int(stdin.readline().rstrip())
l=list(map(int,stdin.readline().split()))
m=int(stdin.readline().rstrip())
k=list(map(int,stdin.readline().split()))
p=[0]
s=0
for i in l:
s+=i
p.append(s)
for i in k:
t=bisect.bisect_left(p, i)
print(t) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | c = lambda:map(int, raw_input().split())
n, a = input(), [0]
b = c()
def f(x):
t = 0
l = 1
r = len(a) - 1
while l <= r:
mid = (l + r) / 2
if(a[mid] >= x): r = mid - 1
else:
t = mid
l = mid + 1
return t
for i in range(n):
a.append(b[i] + a[i])
input()
for x in c():
print f(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 | def bsearch(arr, el):
start = 0
end = len(arr)-1
while(start <= end):
mid = (start+end)//2
mid_el = arr[mid]
if(el < mid_el):
end = mid-1
elif(el > mid_el):
start = mid+1
else:
return mid+1
if(arr[start] > el):
return st... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
for i in range(1,len(a)):
a[i]+=a[i-1]
for i in q:
c=bisect.bisect_left(a,i)+1
print(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 | def sol():
n=int(input())
A=[int(i)for i in input().split()]
m=int(input())
B=[int(i)for i in input().split()]
C=[]
A.insert(0,0)
i=0
j=1
while(j<n+1):
for k in range(i,i+A[j]):
C.append(j)
i+=A[i]
j+=1
#print(C)
for i in range(m):
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_right
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0, n):
b.append(0)
b[i] = b[i-1] + a[i]
k = int(input())
q = list(map(int, input().split()))
for x in q:
print(bisect_left(b, 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 java.util.*;
public class Main
{
public static int search(int[] sums, int l, int h, int x)
{
if(l<h)
{
int mid = l+(h-l)/2;
if(sums[mid]==x)
return mid;
if(sums[mid]>x)
return search(sums,l,mid,x);
else
return search(sums,mid+1,h,x);
}
return l;
}
static Sca... | 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
from bisect import bisect_left, bisect_right
k = input()
pile_sizes = map(int, raw_input().split())
a = len(pile_sizes)
counter = 1
l = []
for r in range(len(pile_sizes)):
l.append(counter)
counter += pile_sizes[r]
b = input()
queries = map(int, raw_input().split())
for k in queries:
print bis... | 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(0);
cin.tie(0);
int n, m, a, q, label = 0, pile[(int)1e6 + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
for (int j = 1; j <= a; j++) {
pile[label + j] = i;
}
label += a;
}
cin >> m;
for (... | 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 findRange(n, li, l, r):
mid = l + (r-l)//2
if abs(r -l) <= 1 :
return r
elif n> li[l] and n <= li[mid]:
return findRange(n, li,l, mid)
else:
return findRange(n, li, mid, r)
n = int(input()) #number of piles
a = [0] + ['' for _ in range(n)]
index = 1
s = 0
for num in map(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 | n = int(input())
a = [int(x) for x in input().split()]
grupos = []
ng = 1
for i in a:
for j in range(i):
grupos.append(ng)
ng += 1
m = int(input())
b = [int(x) for x in input().split()]
for j in b:
print(grupos[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 | from sys import stdin,stdout
def bin(k,lo,hi):
ans=1
while lo<=hi:
mid=(lo+hi)//2
if b[mid]>=k:
ans=mid
hi=mid-1
else:lo=mid+1
return ans
a=int(stdin.readline())
b=[0]+list(map(int,stdin.readline().split()))
stdin.readline();p=""
o=list(map(int,stdin.readline(... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from itertools import accumulate
def bs(ws, w):
i, e = -1, len(ws)-1
while e-i > 1:
m = (e+i)//2
if w <= ws[m]:
e = m
else:
i = m
return e
input()
worms = list(accumulate(map(int, input().split())))
input()
tofind = list(map(int, input().split()))
print("\n".join(s... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # -*- coding: utf-8 -*-
"""
Created on Tue Nov 6 15:10:44 2018
@author: Quaint Sun
"""
n=int(input())
ai=[int(i) for i in input().split()]
m=int(input())
qi=[int(i) for i in input().split()]
for i in range(1,n):
ai[i]=ai[i-1]+ai[i]
for j in range(m):
qi[j]=[qi[j],j]
qi.sort(key=lambda x:x[0])
num=0
t... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
worms = [0]
numbers = list(map(int,input().split()))
for number in numbers:
worms.append(worms[-1]+number)
input()
query = list(map(int,input().split()))
sort = sorted(query)
Dictionary = dict()
queryind = 0
i = 0
while i<len(worms):
if queryind==len(query):
break
if worms[i-1]<sort... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int A[100001];
int binS(int A[], int l, int r, int key) {
if (l >= r) return l;
int mid = (l + r) / 2;
if (A[mid] == key) return mid;
if (key > A[mid]) return binS(A, mid + 1, r, key);
return binS(A, l, mid, key);
}
int main() {
int n, t;
cin >> n;
cin >> 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 bisect as bs
n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
S = [0]
for a in A:
S.append(S[-1] + a)
for b in B:
print(bs.bisect_left(S, 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 java.util.*;
import java.io.*;
public class Solution{
public void run() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
int [] arr = new int[n];
String [] strArr = br.readLine().trim().split(" ");
for(... | JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.