Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int a[10000001], n, m, x;
int main() {
cin >> n;
int beg = 1;
int prev = 0;
for (int i = 0; i < n; i++) {
cin >> x;
for (int j = beg; j <= prev + x; j++) a[j] = i + 1;
prev += x;
beg += x;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> 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 | #include <bits/stdc++.h>
using namespace std;
const unsigned int x = 1000000007;
int n[5] = {0, 1, 2};
map<int, int> m;
int cnt = 0;
int a, b;
int z, y;
int low, high, mid;
void solve(int y) {
while (low <= high) {
mid = (high + low) / 2;
if (m[mid] >= y && m[mid - 1] < y)
return;
else if (m[mid] < ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.StringTokenizer;
public class B474 {
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 | def func(query,low,high):
mid = (low+high)//2
if query <= num_rooms[mid] and query > num_rooms[mid-1]:
return mid
elif query > num_rooms[mid] and query <= num_rooms[mid+1]:
return mid+1
elif query < num_rooms[mid]:
return func(query,low,mid)
elif query > num_rooms[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())
def binarySearch(x,arr,start,end):
if start >= end:
return end
mid = start + (end - start)//2
if arr[mid] == x:
return mid
elif arr[mid] < x:
return binarySearch(x,arr,mid+1,end)
elif arr[mid] > x:
return binarySearch(x,arr,start,mid)
t=list(map(int,input().split()))
csum=[t[0]] #2 values
... | 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.math.*;
import java.io.*;
public class Solution {
static Random random = new Random();
public static void main(String[] args) throws IOException{
FastScanner scanner = new FastScanner(System.in);
int n = scanner.nextInt();
int su... | 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 | L=[]
r=1
input()
for i in input().split():
L+=[r]*int(i)
r+=1
input()
for i in input().split():
print(L[int(i)-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
b=[]
for i in range(n):
b+=[i+1]*a[i]
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 |
import java.util.*;
public class Main{
static int binSearch(int[] arr,int low,int high,int x){
if(low<=high){
int mid=low+(high-low)/2;
// System.out.println(mid);
if((mid>low && arr[mid]>=x && arr[mid-1]<x) || (mid==low && arr[mid]>=x))
return 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;
int main() {
long long n, m;
cin >> n;
long long partialSum[n];
long long sum = 0;
long long x = 0;
while (x < n) {
long long wormQty;
cin >> wormQty;
sum += wormQty;
partialSum[x] = sum;
x++;
}
cin >> m;
long long labelArray[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 | #include <bits/stdc++.h>
using namespace std;
long long n, i, x, q, query, pos;
vector<long long> t;
vector<long long>::iterator iter;
int main() {
ios::sync_with_stdio(false);
cin >> n;
t.push_back(0);
for (i = 1; i <= n; i++) {
cin >> x;
t.push_back(x + t[i - 1]);
}
cin >> q;
for (i = 0; i < 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 | import bisect
def ni():
return int(raw_input())
def nis():
return map(int, raw_input().split())
def si():
return raw_input()
n = ni()
a = nis()
m = ni()
q = nis()
for i in range(n - 1):
a[i + 1] += a[i]
ans = []
for x in q:
ans.append(str(bisect.bisect_left(a, x) + 1))
print '\n'.join(ans) | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [int(i) for i in input().split()[:n]]
m = int(input())
q = [int(j) for j in input().split()[:m]]
v = []*n
w = []
z1 = []
x1=0
x2=0
for k in range(n):
s1 = 1+x1
s2 = a[k]+x2
x1 = s2
x2 = x2+a[k]
v.append([s1,s2])
z1.append(s1)
# print(v)
def binary_search(arr, x):
low... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n= int(input())
a= [int(i) for i in input().split()]
m= int(input())
q= [int(i) for i in input().split()]
b= q.copy()
b.sort()
c={}
i, j= 0, 0
w=0
while i<len(q) and j<len(a):
if w< b[i]<= w+a[j]:
c[b[i]]= j+1
i+=1
elif b[i] > w+a[j]:
w+= a[j]
j+=1
for i in q:
print(c[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 | def GetWorms(worms):
w = [1]
s = worms[0]
for i in range(1,len(worms)):
w.append(s+1)
s += worms[i]
return w
def Solve(worms,label,maxx):
low = 0
high = len(worms)-1
while low <= high:
mid = (low+high)//2
if label > worms[mid]:
low = 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 | import java.io.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;
public class Main implements Runnable {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.io.*;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class wormsTreeMap {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
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 | R=lambda:map(int,raw_input().split())
n,a,m,b=input(),R(),input(),R()
index,s=[0]*(sum(a)+1),1
for i in range(n):
for j in range(a[i]):
index[s+j]=i+1
s+=a[i]
print '\n'.join(map(str,[index[x] for x in b])) | 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())
lin = list(map(int, input().split()))
mw = {}
pile = 1
wty = 0
for i in lin:
j = i
while j:
wty += 1
mw[wty] = pile
j -= 1
pile += 1
m = int(input())
lim = list(map(int, input().split()))
for i in lim:
print(mw[i]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import os
import sys
from io import BytesIO, IOBase
from itertools import accumulate
from bisect import bisect_left
def solution(arr, brr, n, m):
arr = list(accumulate(arr))
for q in brr:
write(bisect_left(arr, q) + 1)
def main():
n = r_int()
arr = r_array()
m = r_int()
brr = r_array... | 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
stdin=sys.stdin
def sol1():
n=int(stdin.readline().strip())
a=map(int,stdin.readline().strip().split())
s=[0]*(10**6+1)
curr=0
for i in range(n):
for j in range(a[i]):
s[curr]=i
curr+=1
m=int(stdin.readline())
for q in map(int,stdin.readline()... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
queries=list(map(int, input().split()))
ans = []
for i in range(n):
ans+=[i]*a[i]
#print(ans)
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 | n = int(input())
ai = input().split()
m = int(input())
qi = input().split()
ai[0] = int(ai[0])
for i in range(1, n):
ai[i] = int(ai[i]) + int(ai
[i - 1])
for i in range(m):
qi[i] = int(qi[i])
left = 0
right = n
while right > left:
mid = (right + left) ... | 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 binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <= key):
count = mid+1
left = mid + 1
# If 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 | n = int(input())
a = list(map(int, input().rsplit()))
m = int(input())
q = list(map(int, input().rsplit()))
b = []
a0 = 0
for i in range(n):
j = a0 + 1
while j <= a[i] + a0:
b.append(i + 1)
j += 1
a0 = a[i]
for j in range(m):
print(b[q[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 | function sum(array){
var result = 0;
for(var i = 0; i < array.length; i++){
result += +array[i];
}
return result;
}
var n = +readline(), a = readline().split(" ").map(Number), m = +readline(),
q = readline().split(" ").map(Number);
var array = [], all = sum(a), cnt = a[0];
for(var i = 1, j = 1; i <= all; 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 | l=[]
n=input()
a=map(int,raw_input().split(' '))
for i in range(n):
l+=[i+1]*a[i]
m=input()
q=map(int,raw_input().split(' '))
for i in range(m):
print l[q[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 | #include <bits/stdc++.h>
using namespace std;
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const long long N = 1e6 + 10;
long long pile[N];
void solve() {
long long n;
cin >> n;
long long a, curr = 1, sum = 0;
for (long long i = 0; i < n; i++) {
cin >> a;
sum +=... | 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 search(a, x):
l, r = 0, len(a) - 1
while l <= r:
mid = (l + r) // 2
if a[mid] >= x and a[mid - 1] < x:
return mid
elif a[mid] < x:
l = mid + 1
else:
r = mid - 1
return 0
n = int(input())
a = list(map(int, input().split()))
for i in ran... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Scanner;
public class Worms {
private static int arr[];
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
arr = new int[n];
arr[0] = sc.nextInt();
for (int i = 1; i < n; i++)
arr[i] = arr[i ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def func(arr,x):
i=0
j=len(arr)-1
while i<=j:
mid=(i+j)//2
if mid==0:
if x>=1 and x<=arr[mid]:
return mid+1
else:
return mid+2
if x<=arr[mid] and x>=arr[mid-1]+1:
return mid+1
elif x>arr[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 bisect
n = int(input())
worms = list(map(int, input().split(' ')))
m = int(input())
labels = list(map(int, input().split(' ')))
pile_labels = []
for i in range(len(worms)):
if i == 0:
pile_labels.append(worms[0])
else:
value = pile_labels[i - 1] + worms[i]
pile_labels.append(val... | 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.... | 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;
cin >> n;
int arr[n];
int z = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
z += arr[i];
arr[i] = z;
}
cin >> m;
for (int j = 0; j < m; j++) {
cin >> z;
z = lower_bound(arr, arr + n, z) - arr;
cout << z + 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 itertools import accumulate
def bin_search(x, left, right, num_list):
if right - left <= 1:
if x <= num_list[left]:
return left + 1
else:
return right + 1
else:
middle = (left + right) // 2
if x < num_list[middle]:
return bin_search(x, l... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int binSearch(int a, int* numSet, int setSize) {
int initial = 0;
int final = setSize - 1;
int i = 0;
while (true) {
i++;
if (i == 20) break;
int mid = initial + (final - initial) / 2;
if (final - initial <= 1) {
if (a < numSet[final] && a > nu... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, m, k;
while (scanf("%d", &n) != EOF) {
a[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] += a[i - 1];
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &k);
printf(... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
ls = []
zzh = []
zzh.append(0)
ls = [int(u) for u in input().split()]
for item in range(len(ls)):
for _ in range(ls[item]):
zzh.append(item+1)
m = int(input())
inp = [int(u) for u in input().split()]
for u in inp:
print(zzh[u])
| 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.awt.Point;
import java.util.Scanner;
public class imp {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
// get number of piles
// max n -> 10^5
int n = s.nextInt();
int read;
// max ai -> 10^6
Point[] piles = new Poi... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
res = []
for i in range(n):
res += [i] * a[i]
for x in b:
print(res[x-1] + 1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
long long int n, sum = 0, t;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
sum += t;
vec.push_back(sum);
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
if (t <= vec[0]) {
cout << "1\n";
conti... | 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[] args) {
Scanner sc = new Scanner(System.in);
int n, m;
int[] a;
n = sc.nextInt();
a = new int[n];
int sum = 0;
for (int i = 0; i < n; i++) {
sum += sc.nextInt();
a[i] = sum;
}
m = sc.nextInt();
for (int 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 n, a[100000], m, q, sp[100000];
int cautbin(int val) {
int left = 0, right = n - 1, best = -1;
while (left <= right) {
int mid = (left + right) / 2;
if (sp[mid] >= val) {
best = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
int m;
cin >> m;
while (m--) {
int x;
cin >> x;
int l = -1, r = n + 1;
while (r - l > 1)... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[n], s[n];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
sum += ar[i];
if (i == 0)
s[i] = 1;
else
s[i] = s[i - 1] + ar[i - 1];
}
int st[sum + 1];
int p = 1;
for (int i = 0; i < n; i... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | N = input()
A = list(map(int, raw_input().split(' ')))
M = input()
Q = list(map(int, raw_input().split(' ')))
B = [A[0]]
for i in xrange(N-1) :
B.append(A[i+1]+B[-1])
for i in Q :
l = 0
r = len(B)-1
while True :
if l == r : break
m = (l+r)//2
if i <= B[m] :
r = m
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n;
int a[n], sum[n];
sum[0] = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum[i + 1] = sum[i] + a[i];
}
int j;
n += 1;
cin >> w;
while (w--) {
cin >> j;
cout << (lower_bound(sum, sum + n, j) - sum) << 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 | n = int(raw_input())
a = map(int, raw_input().split())
m = int(raw_input())
q = map(int, raw_input().split())
"""
5
2 7 3 4 9
3
1 25 11
idx 0 1 2 3 4 5
prefix_sums: 0 2 9 12 16 25
"""
prefix_sums = [0]
curr_sum = 0
for i in xrange(len(a)):
curr_sum+=a[i]
prefix_sums.append(curr_sum)
#check: if ... | 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 | g=int(input())
b = [int(x) for x in input().split()]
lookup=[]
group_no=0
for x in b:
group_no +=1
for j in range(x):
lookup.append(group_no)
c=int(input())
d=[int(x) for x in input().split()]
for x in d:
print(lookup[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 |
def main_tle():
raw_input()
A = [int(i) for i in raw_input().split(" ")]
raw_input()
B = [int(i) for i in raw_input().split(" ")]
Bv2i = {}
for i in range( len(B) ):
if B[i] not in Bv2i:
Bv2i[B[i]] = []
Bv2i[B[i]].append(i)
B.sort()
R = [0]*len(B)
pn = 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;
signed main() {
long long n, m, x, ans = 0;
cin >> n;
long long arr[n + 1];
arr[0] = 1;
cin >> arr[1];
for (long long i = 2; i < n + 1; i++) {
cin >> x;
arr[i] = arr[i - 1] + x;
}
cin >> m;
long long q[m];
for (long long 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 |
# num piles
n = int(raw_input())
piles = raw_input().split()
m = int(raw_input())
queries = raw_input().split()
piles = [ int(x) for x in piles ]
queries = [ int(x) for x in queries ]
#algorithm - make an array of size sum(piles)
total = sum(piles)
storage = [0]*total
#fill in the indexes
counter = 0
for i in ran... | 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 bs(int ar[], int le, int ri, int x) {
int mid;
mid = (le + ri) / 2;
if (ri >= le) {
if (x == ar[mid])
return mid;
else if (x < ar[0])
return 0;
else if (x < ar[mid] && x > ar[mid - 1]) {
return mid;
} else if (x > ar[mid] && 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 | from sys import stdin, stdout
from itertools import repeat
def main():
n = int(stdin.readline())
a = map(int, stdin.readline().split(), repeat(10, n))
m = int(stdin.readline())
q = map(int, stdin.readline().split(), repeat(10, m))
q = [(x, i) for i, x in enumerate(q)]
q.sort()
ans = [0] * m
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a[1000003], n, x = 1, t;
cin >> n;
for (int i = 1; i < n + 1; i++) {
cin >> t;
while (t--) {
a[x] = i;
x++;
}
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> t;
cout << a[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 | n = raw_input()
numberOfWorms = map(int, raw_input().split())
m = input()
juicyWorms = map(int, raw_input().split())
totalWorms = []
totalWorms.append(numberOfWorms[0])
for i in range(1,len(numberOfWorms)):
totalWorms.append(numberOfWorms[i] + totalWorms[i-1])
# print(totalWorms)
# print(juicyWorms)
for i in 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 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
d = {}
t = 1
for i in range(n):
for j in range(t, t + a[i]):
d[j] = i + 1
t += a[i]
for i in range(m):
print(d[b[i]])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, numbers1;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> numbers1;
a[i] = numbers1;
}
int m, numbers2;
cin >> m;
int q[m];
for (int i = 0; i < m; i++) {
cin >> numbers2;
... | 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 | '''
my bibary search didn't work
'''
# ossan
def bin_search(li, k, l, h):
m = (l + h) // 2
if k == li[m]:
return m+1
elif li[m-1] < k < li[m] and m != 0:
return m+1
elif k < li[m] and m == 0:
return m+1
elif k > li[m] and m == len(li)-1:
return m+1
elif k > li[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 | ######
n = int(input())
piles = list(map(int, input().split()))[:n]
juicy_number = int(input())
juicy = list(map(int, input().split()))[:juicy_number]
worms = [piles[0]]
j = 0
for i in range(1, len(piles)):
number_two = worms[j] + piles[i]
worms.append(number_two)
j += 1
def binarySearch(arr, l, r, x):
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n;
int[] ai;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
ai = new int[n];
for (int i = 0; i < n; i++) {
ai[i] = sc.nextInt();
}
for (int i = 1; i < n; i++)... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin
def main():
arr=[]
cnte=1
cnte2=1
arr.append(int(0))
stdin.readline()
for i in map(int,stdin.readline().split()):
for j in range(0,i):
arr.append(cnte2)
cnte2=cnte2+1
stdin.readline()
for i in map(int,stdin.readline().split()):
pr... | 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())
p=map(int,raw_input().split())
m=int(raw_input())
a=map(int,raw_input().split())
K=[0]
for i in range(n):
K.extend([i+1]*p[i])
for j in a:
print K[j]
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(input())
vals = [*map(int, input().split())]
m = int(input())
queries = [*map(int, input().split())]
# Finding cumulative
for i in range(1, n):
vals[i] += vals[i-1]
for query in queries:
print(bisect.bisect_left(vals, query) + 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 st[100005];
long bSearch(long v, long s, long e) {
long mid;
while (s <= e) {
mid = (s + e) / 2;
if (st[mid] == v)
return mid;
else if (st[mid] <= v && st[mid + 1] > v)
return mid;
else if (st[mid] > v && st[mid + 1] > v) {
e = 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 | def sortFst(val):
return val[0]
def sortScd(val):
return val[1]
a = int(input())
b = input().split()
c = int(input())
d = input().split()
dtrix = []
for i in range(len(d)):
dtrix.append([int(d[i]), i, 0 ])
dtrix.sort(key = sortFst)
matrix = []
atual = 0
for i in b:
matrix.append([atual+1, atual + 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.*;
import java.util.*;
public class Solution
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
int sum=0;
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
sum=sum+arr[i];
}
int dp[]=new int[su... | 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,raw_input().split()))
N2=int(input())
A2=list(map(int,raw_input().split()))
con=0
Numeros=1
Matriz=[]
for k in A:
con+=1
for j in range(k):
Matriz.append([Numeros,con])
Numeros+=1
for i in A2:
print Matriz[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, a, m, b, e = input(), [int(i) for i in input().split()], input(), [int(i) for i in input().split()], []
for i in range(len(a)):
for j in range(a[i]):
e.append(i+1)
for i in b:
print(e[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin,stdout
inpt = lambda: stdin.readline().strip()
prnt = lambda x: stdout.write(str(x)+'\n')
def find_res(a,q):
Li = []
r = 1
for i in a:
Li+=[r]*i
r+=1
for i in q:
prnt(Li[i-1])
def main():
inptf = inpt
inptf()
a = map(int,inpt().split())
inpt... | 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())
worms = list(map(int, input().split()))
worms_count = [0]
for w in worms:
worms_count.append(worms_count[-1] + w)
# print(*worms_count)
m = int(input())
juicy = list(map(int, input().split()))
for j in juicy:
print(bisect_left(worms_count, 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 | piles = int(input())
number_of_worm_in_each_pile = [int(i) for i in input().split()]
number_of_juicy_worm = int(input())
label_of_juicy_worm = [int(i) for i in input().split()]
pile = 1
worm_repo = []
counter = 0
for i in range(piles):
for j in range(1,number_of_worm_in_each_pile[counter]+1):
worm_repo.append(... | 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.Arrays;
public class Worms {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Inte... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.Scanner;
public class pfffff {
static PrintWriter out = new PrintWriter(System.out);
static Scanner in = new Scanner(System.in);
static int bs(int[] a1, int[] a2, int L, int R, int key){
while (L <= R){
int mid = L + ((R - L) >> 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 | import bisect
n = int(input())
ls = list(map(int,input().split()))
for i in range(1,n):
ls[i]+= ls[i-1]
q = int(input())
lq = list(map(int,input().split()))
for item in lq:
print(bisect.bisect_left(ls,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 | num1 = int(input())
list1 = [int(k) for k in input().split()]
num2 = int(input())
list2 = [int(k) for k in input().split()]
sum_list = [0] * (num1 + 1)
for k in range(num1):
sum_list[k+1] = sum_list[k] + list1[k]
def binary_search(list, num):
first_bound = 0
last_bound = len(list) - 1
while True:
... | 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-1]
from bisect import bisect_left
for i,x in enumerate(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 | #include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n;
cin >> n;
int sum = 1;
vector<int> v;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
v.push_back(sum);
}
v.push_back(sum + 1);
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x;
sc... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
arr = list(map(int,input().split()))
for i in range(1,n):
arr[i]+=arr[i-1]
q = int(input())
query = list(map(int,input().split()))
d = {}
for i in query:
d[i] = 0
temp = query[::]
temp.sort()
ans = []
cnt = 0
for i in temp:
while i>arr[cnt]:
cnt+=1
d[i] = cnt+1
for i in query:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def bs(v, a):
lo, hi = 0, len(a) - 1
r = -1
while lo <= hi:
mi = lo + (hi - lo)//2
if a[mi] >= v:
r = mi
hi = mi - 1
else:
lo = mi + 1
return r
n = int(input() )
a = list(map(int, input().split() ) )
for i in range(1, n): a[i] += a[i-1]
input(... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.Scanner;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static int nextInt()throws IOException{
in.nextToken();
return (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.*;
import java.io.*;
public class TaskB {
private FastScanner in;
private PrintWriter out;
public void solve() throws IOException {
int n = in.nextInt();
int[] num = new int[(int) 2e6];
int cur = 0;
for (int i = 0; i < n; i++) {
int val = 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 | #include <bits/stdc++.h>
using namespace std;
const int M = 1000 * 1000 + 1000;
int n;
int a[M];
int m;
int q[M];
int sum[M];
int search(int f, int e, int k) {
if (f == e) return f;
int mid = (f + e) / 2;
if (sum[mid] >= k) return search(f, mid, k);
return search(mid + 1, e, k);
}
int main() {
cin >> n;
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())
worms = [int(x) for x in input().split()]
m = int(input())
jucy = [int(x) for x in input().split()]
label = []
i = 1
for x in worms:
for j in range (0, x):
label.append(i)
i+=1
for x in jucy:
print(label[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 sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
n_worms = inp()
worms = inl... | 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())
m = input()
q = map(int,raw_input().split())
f = [0]
for i in range(n): f += [i+1]*a[i]
for i in q: print f[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 | n = int(input())
l = list(map(int,input().split()))
a = []
k = 1
mp = {}
for i in range(n):
for j in range(k,k+l[i]):
mp[j] = i+1
k = k + l[i]
m = int(input())
q = list(map(int,input().split()))
for value in q:
print(mp[value])
| 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 Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int [] n = new int [input.nextInt()] ; int sum =0;
for (int i =0 ; i <n.length ; i++){
n[i]= input.nextInt();
sum+=n[i];}
int [] x = new int [sum];
int in=0;
... | 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 -*-
#αββαββα HELLO HELLO HELLO αββαββα
n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
m = int(raw_input())
q = list(int(i) for i in raw_input().strip().split(" "))
t = range(n+1)
t[0] = 0
for i in range(1,n+1):
t[i] = a[i-1] + t[i-1]
for i in q:
s = 1
e = ... | 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 | trash = int(input());
firstLine = [int(x) for x in input().split()];
trash = int(input());
secondLine = [int(x) for x in input().split()];
worms = [];
for i in range(0, len(firstLine)):
for j in range(0, firstLine[i]):
worms.append(i);
for i in secondLine:
print(worms[i-1]+1);
'''for i in range(1, le... | 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();rows=map(int,raw_input().split());q=input()
quer=sorted(enumerate(map(int,raw_input().split())),key=lambda x:x[1])
ans=[0]*q;sums=[rows[0]]+[0]*(n-1);ct=0
for i in xrange(1,n):
sums[i]=sums[i-1]+rows[i]
for k,v in quer:
while sums[ct]<v:
ct+=1
ans[k]=str(ct+1)
print "\n".join(ans)
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class Main
{
static int[][] grid;
static int n ;
static ArrayList<Integer> adj ;
static HashMap<Integer,Integer> hm;
public static void main( String args[] )
{
MyScanner sc = new MyScanner();
n = sc.nextInt();
hm = new HashMap<Integer,Integer>();
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>
const int MAXN = 100 + 10;
const int MAXT = 100000 + 10;
const int INF = 0x7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-6;
using namespace std;
int n, a[MAXT], l[MAXT], r[MAXT], q;
void init() {
l[0] = 1;
r[0] = a[0];
for (int i = 1; i < n; ++i) {
l[i] = r[i - 1] + 1;... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct query {
int x, id;
} q[N];
int n;
int a[N];
int sum = 0, uk = 0;
int m;
int ans[N];
bool cmp(query A, query B) { return A.x < B.x; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
scanf("%d", &m);
for (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 | import bisect
from bisect import bisect_left
from bisect import bisect_right
n = input()
a = map(int, raw_input().split())
m = input()
for i in range(1, n): a[i] += a[i-1]
a.insert(0, 0)
for i in map(int, raw_input().split()):
print bisect.bisect_left(a, 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 | import sys
input = sys.stdin.readline
def main():
int(input())
heaps = list(map(int, input().split()))
sum = 0
i = 0
while i < len(heaps):
heaps[i] = sum + heaps[i]
sum = heaps[i]
i += 1
int(input())
es = list(map(int, input().split()))
for e in es:
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())
p = {}
pn = 1
for i, n in enumerate(input().split()):
n = int(n)
for ni in range(pn, pn + n):
p[ni] = i + 1
pn = pn + n
j = int(input())
for jw in input().split():
jw = int(jw)
print(p[jw])
| 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 | num_piles = int(input())
worm_piles = list(map(int, input().split()))
num_juicy_worms = int(input())
juicy_worm_labels = list(map(int, input().split()))
bins = [] # ith num is min for the bin
running_sum = 1
for i in range(1, num_piles + 1):
if i == 1:
bins.append(running_sum)
running_sum += worm_... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int p[n];
cin >> p[0];
for (int i = 1; i < n; i++) {
int x;
cin >> x;
p[i] = p[i - 1] + x;
}
int t;
cin >> t;
while (t--) {
int key;
cin >> key;
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 | a=int(input())
b= list(map(int,input().split()))
c=int(input())
d= list(map(int,input().split()))
for k in range(1,a):
b[k] += b[k-1]
for j in d:
l=0
r= a-1
while l<= r:
if j <= b[0]:
mid=0
break
mid= (l+r)//... | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.