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 | import java.util.Scanner;
import java.io.PrintWriter;
public class Worms {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
if (i == 0) arr[i] = in.nextI... | 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.awt.*;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Map.Entry;
import static java.lang.Math.*;
public class solver implements Runnable {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out... | 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;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.begin();
}
private int n;
private int[] s;
private int[] e;
private void begin() {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
s = new int[n];
e =new int[n];
int c... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.*;
public class Main implements Runnable {
public final String TASKNAME = "";
public final boolean CONSOLE = true;
public static void main(String[] args) {
new Thread(new Main()).start();
}
BufferedReader br;
PrintWriter out;
StringTokenizer 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 bb(alist,item):
res=-1
first=0
last=len(alist)-2
found=False
while first<=last and not found:
midpoint=(first+last)/2
if alist[midpoint]<item and alist[midpoint+1]>=item:
found=True
res=midpoint
else:
if item<=alist[midpoint]:
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Scanner;
public class Main {
public int binary(int a[], int l, int r, int x){
if (r>=l){
if (x<=a[0]){
return 0;
}
int mid = l+(r-l)/2;
if (x <= a[mid] && x > a[mid-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;
const int A = 1e5 + 5;
long long int n, a[A], s[A], q, x, l, r, mid;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
s[i] = (s[i - 1] + x);
}
cin >> q;
for (int i = 1; i <= q; i++) {
cin >> x;
l = 1;
r = n;
while (l != r - 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 = 1e5 + 7;
int n, m, ans, a[N], sum, x;
map<int, int> map1;
vector<pair<int, int>> p;
set<int> set1;
int main() {
cin >> n >> a[0];
p.push_back({1, a[0]});
for (int i = 1; i < n; i++) {
cin >> a[i];
p.push_back({p[i - 1].second + 1, a[i] + p[i - 1]... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Scanner;
import java.util.*;
public class Solution {
public static void main(String[] args) {
boolean debug = false;
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] a = new int[n];
for(int i=0; i < n; i++) {
a[i] = input.nextInt();
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | /*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codeforce {
public static void main (String[] args) {
FastReader fr = new FastReader();
int n = fr.nextInt();
int[] a = new int[n];
for(int i = 0;i < n;i++) {
a[i... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int numOfPils, NumOfGood;
cin >> numOfPils;
int(*arrayOfPils)[3] = new int[numOfPils][3];
int temp = 0;
for (int i = 0; i < numOfPils; i++) {
cin >> arrayOfPils[i][0];
if (i == 0) {
arrayOfPils[0][1] = 1;
arrayOfPils[0][2] = arrayO... | 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()]
m = int(input())
q = [int(x) for x in input().split()]
worms = [0]*(10**6+1)
s = 1
for i in range(n):
worms[s:s+a[i]] = [i+1]*a[i]
s = s+a[i]
for i in q:
print(worms[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())
wormst = list(map(int, input().split()))
soma = sum(wormst)
worms = [0] * (soma + 1)
pre = 0
for i in range(len(wormst)):
start = pre + 1
end = start + wormst[i] - 1
pre = end
for k in range(start, end + 1):
worms[k] = i + 1
q = int(input())
queries = list(map(int, input().split... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from math import ceil
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)
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | a=int(input())
l=list(map(int,input().split()))
r=1
m=[]
for i in l:
m+=[r]*i
r+=1
b=int(input())
n=list(map(int,input().split()))
for i in n:
print(m[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 bisect
n=int(input())
a=[int(v) for v in input().split()]
m=int(input())
q=[int(v) for v in input().split()]
for i in range (1,n):
a[i]+=a[i-1]
for i in range (0,m):
print(bisect.bisect_left(a,q[i])+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, sum(0);
cin >> n;
int counts[n];
for (int i = 0; i < n; i++) {
cin >> t;
sum += t;
counts[i] = sum;
}
int ind(0), worms[sum + 1];
for (int i = 1; i <= sum; i++) {
if (i > counts[ind]) ind++;
worms[i] = ind + 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.Hashtable;
import java.util.Scanner;
public class Worms {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int acc=0;
int [] ind = new int[1000001];
for(int i=0;i<N;i++) {
int a = in.nextInt();
for(int j=0;j<a;j++)
ind[++acc]=i+1... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
aI = map(int, raw_input().split())
mJuicy = int(raw_input())
qPos = map(int, raw_input().split())
arr = []
for v in aI:
if len(arr) == 0:
arr.append(v)
else:
arr.append(arr[-1] + v)
l = 0
for i in qPos:
l = 0
r = len(arr)
while l < r:
mid = (l + r) // 2... | 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 | # Taking the input
batches = input()
worms = map(int,raw_input().split())
demands = input(); count = 0
guesses = map(int,raw_input().split())
# Processing
batchMap = [0];
for w in worms:
count +=1
for m in range(w):
batchMap.append(count)
# Output
for g in guesses:
print batchMap[g] | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B474_Worms {
public static void main(String[] args) {
PrintWriter pw = new PrintWriter(System.out);
int n = nextInt();
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 | //package com.codeforces.p474;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main {
private StreamTokenizer in;
private PrintWriter out;
private ... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
public class solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
int[] ac=new int[n];
int sum=0;
for(int i=0;i<n;i++) {
ac[i]=sc.nextInt();
sum+=ac[i];
a[i]=sum;
}
int m=sc.nextInt();
int[] q=new... | 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, exit
n = int(stdin.readline().rstrip())
piles = list(map(int, stdin.readline().rstrip().split(' ')))
m = int(stdin.readline().rstrip())
labels = list(map(int, stdin.readline().rstrip().split(' ')))
cur = 1
ranges = []
for pile in piles:
ranges.append((cur, cur + pile - 1))
cur += 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 bisect
n=int(input())
l1=list(map(int,input().split()))
for i in range(1,len(l1)):
l1[i]=l1[i]+l1[i-1]
m=int(input())
l2=list(map(int,input().split()))
for i in l2:
print(bisect.bisect_left(l1,i)+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
n = int(input())
a1 = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
a2 = [1, a1[0]]
for i in a1[1:]:
a2.append(a2[-1] + 1)
a2.append(a2[-1] + i - 1)
def bins(key):
l = 0
r = len(a2) - 1
while r > l + 1:
m = (r + l) // 2
if key <= a2[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 | def pro():
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
sm = []
p = 0
for i in range(n):
p += a[i]
sm.append(p)
def bs(q,o):
l = -1
r = n
while r - l > 1:
m = (r + l) // 2
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | input()
data = list(map(int, input().split(' ')))
temp = []
t = 0
for i in data:
t += i
temp.append(t)
input()
search_data = list(map(int, input().split(' ')))
sorted_search_data = sorted(search_data)
res = {}
len_search_data = len(search_data)
j = 0
for i in sorted_search_data:
while i > temp[j]:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.ArrayList;
import java.util.Scanner;
import java.io.* ;
import java.util.regex.* ;
import java.text.*;
public class B_474 {
class Pair<T>
{
T first;
T second;
public Pair(T first,T second)
{
this.first=first;
this.second=second;
}
}
public static void BS(ArrayList<Pair<Integer>> ... | 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 | #TLE in python. But Accepted in cpp using same algorithm :(
n=input()
ar=map(int,raw_input().split())
sum=0
for i in range(0,n):
sum+=ar[i]
ar[i]=sum
m=input()
q=map(int,raw_input().split())
for x in q:
low=0
high=n-1
while(low<high):
mid=(low+high)/2
if(ar[mid]<x):
low=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;
static int n, m, a, q;
static int partial[100001];
int find_position(int k) {
int a = 0;
int b = n - 1;
while (a < b) {
if (partial[(a + b + 1) / 2] >= k)
b = (a + b + 1) / 2 - 1;
else
a = (a + b + 1) / 2;
}
return a;
}
int main() {
cin >> n;... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(input())
s = input().split(" ")
a = [0] * n
for x in range(n):
a[x] = int(s[x])
d = []
c = 0
for x in range(n):
d.append(c + a[x])
c += a[x]
p = int(input())
s = input().split(" ")
m = [0] * p
for x in range(p):
m[x] = int(s[x])
for x in range(p):
mid = (bisect.bisect_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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m, j, cnt = 0, ans, x, sum = 0;
cin >> n;
int a[n], c[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
c[i] = sum;
}
cin >> m;
int b[m];
for (i = 0; i < m; i++) cin >> b[i];
for (j = 0; j < m; j++) {
cout << lo... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import j... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin, stdout
def c_r(arr, l, r, target):
while l + 1 < r:
m = (l + r) // 2
if arr[m] >= target:
r = m
else:
l = m
return r
def main():
n = int(stdin.readline().strip())
A = [int(num) for num in stdin.readline().strip().split()]
P_A =... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
# CODE BEGINS HERE.................
def search(l,i,p1,p2):
mid =int((p1+p2)/2)
# print(l[mid])
if(l[mid]==i):
return mid+1
elif(i<l[mid]):
if(mid==0):
return 1
if(l[mid-1]+1<=i):
return mid+1
else:
return search(l,i,p1,mid)
else:
if(l[mid+1]>=i):
return mid+2
else:
return search(l,i,mi... | 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 -*-
def cumulative_sum(array):
sum = [array[0]]
for i in xrange(1, len(array)): sum.append(sum[i - 1] + array[i])
return sum
def binary_search(array, number):
i, j = 0, len(array)
position = -1
while i <= j:
m = (i + j) / 2
middle = array[m]
if mi... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | ## 474B
n=int(input())
a=list(map(int,input().split()))
m=int(input())
l=list(map(int,input().split()))
v=[]
r=0
for i in range(n):
v.append(a[i]+r)
r+=a[i]
# print(v)
def bins(v,t):
start=0
end=len(v)-1
i=0
index=0
while start<=end:
mid=(start+end)//2
if t<=v[0]:
return 1
else:
if v[mid]>=t and v... | 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 bsearch(arr,target):
start =0
end = len(arr)-1
while(start<=end):
mid = ((start+end)//2)
if target>arr[mid]:
start=mid+1
elif target<arr[mid]:
end = mid -1
else:
return mid
return start
n = int(input())
a1 = list(map(int,input().spl... | 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 *
from collections import *
from operator import *
from bisect import *
from fractions import *
Ii = lambda: map(int, raw_input().split())
Is = lambda: raw_input().split()
ri = raw_input
def prefix_sums(A):
# sum(A[l:r]) = B[r]-B[l]
B = [0]*(len(A)+1)
for i in xrange(len(A)):
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def worms_find(find):
left = -1
right = len(piles_p)
while left + 1 <right:
mid = left + (right - left)//2
if piles_p[mid] == find:
right = mid
break
elif piles_p[mid] > find:
right = mid
else:
left = mid
return righ... | 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 | #comment to pass 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(left<=righ... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
int a[MAX_N];
int q[MAX_N];
int c[2000005];
int main() {
int n, m;
cin >> n;
int s = 0;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
for (int j = 0; j < a[i]; j++) {
c[++cnt] = i;
}
}
vector<int> v;
ci... | 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 collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, ... | 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())
arr=list(map(int,input().split()))
prefix_sum=[0]
for i in arr:
prefix_sum.append(prefix_sum[-1]+i)
# print(prefix_sum)
q=int(input())
# l=list(map(int,input().split()))
for i in map(int,input().split()):
pos=bisect_left(prefix_sum,i)
print(pos)
| 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
#####################################################################
def iinput(): return int(stdin.readline())
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
####################################... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(input())
worms = 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 = 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 | n = int(input())
a = []; q = []; b = []
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, b[100000], a[100000], i, j = 0, k = 1, ans = 1;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
cin >> m;
for (i = 0; i < m; i++) cin >> b[i];
for (i = 1; i < n; i++) a[i] = a[i] + a[i - 1];
for (i = 0; i < m; i++) {
k = b[i];
if ... | 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 |
#------------------------template--------------------------#
import os
import sys
from math import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
... | 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 | # 474B: Worms
# Find element or nearest greater than element
def binary_search(a, l, r, e):
if l >= r:
if e > a[l]:
return l + 1
else:
return l
else:
mid = (l + r) / 2
if e == a[mid]:
return mid
elif e > a[mid]:
return bina... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n=input()
b=list(map(int,input().split()))
for i in range(1,len(b)):
b[i]+=b[i-1]
m=int(input())
t=list(map(int,input().split()))
for i in t:
a=bisect_left(b,i)
if a==len(b):
print(n)
else:
print(a+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, m;
cin >> n;
long long int k[100001];
k[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a;
k[i] = k[i - 1] + a;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a;
int ml = 1, mr = n, mid;
while (ml <= mr) {
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.util.Scanner;
import java.lang.Math;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Worms{
private static long[] piles;
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamRea... | 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())
s = list(map(int, input().split()))
m = int(input())
p = list(map(int, input().split()))
a = []
count = 0
for i in range(n):
count += s[i]
a.append(count)
for i in p:
print(bisect.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 | def find(num):
lo = 0
hi = len(s) - 1
while (lo < hi-1):
mid = (lo + hi) / 2
if s[mid] < num: lo = mid
elif s[mid] == num: return mid
else: hi = mid
if (s[lo] >= num): return lo
return hi
n = int(raw_input())
a = map(int,raw_input().split())
s = [0]*n
s[0] = a[0]... | 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()]
m = int(input())
qs = [int(i) for i in input().split()]
cs = 0
pref_sums = []
for i in a:
pref_sums.append(cs+i)
cs += i
ans = []
for q in qs:
l = -1
r = n - 1
while r - l > 1:
m = l + (r - l) // 2
if pref_sums[m] < 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;
long long binarySearch(int arr[], long long l, long long r, long long x) {
if (r > l) {
long long mid = l + (r - l) / 2;
if (arr[mid] >= x)
return binarySearch(arr, l, mid, x);
else
return binarySearch(arr, mid + 1, r, x);
} else {
return r;
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(input())
arr = list(map(int,input().split()))
for i in range(1,n):
arr[i] += arr[i-1]
m = int(input())
q = list(map(int, input().split()))
for i in range(m):
ans = bisect_left(arr,q[i])
print(ans+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, x, sum = 0, q;
vector<int> v;
vector<int>::iterator it;
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
sum += x;
v.push_back(sum);
}
int sz = v.size();
scanf("%d", &q);
while (q--) {
scanf("%d", &x);
it = lower_boun... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
I = lambda: input()
R = lambda: map(int, raw_input().split())
n = I()
a = R()
w = 0
for i in range(n):
w += a[i]
a[i] = w
m = I()
for n in (R()):
print bisect_left(a, n) + 1
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from sys import stdin, stdout
def search(lst, x, end, beg=0):
mid = (beg+end)//2
a, b = lst[mid]
if a<=x and x<=b:
return mid
if not (beg < end):
return -1
if x < a:
return search(lst, x, mid-1, beg)
if x > b:
return search(lst, x, end, mid+1)
lst_a, be... | 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 | x=int(input())
a=list(map(int,input().split()))
y=input()
b=list(map(int,input().split()))
c=[]
d=1
for i in a:
for j in range(i):
c.append(d)
d+=1
for i in b:
print(c[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 | /*
ID: jeromej1
LANG: JAVA
PROG: 474B
*/
import java.io.*;
import java.util.*;
public class FourSevenFourB
{
int piles;
int[] pileSizes;
int juicy;
int[] juicies;
public FourSevenFourB() throws Exception
{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
piles = Integer.parseI... | 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 N = 1e5 + 5;
int n, m;
int a[N];
set<pair<int, int> > s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
pair<int, int> p = {a[i], i};
s.insert(p);... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
a= int(raw_input())
data= map(int,raw_input().split())
b= int(raw_input())
juicy= map(int,raw_input().split())
piles =[data[0]]
for i in xrange(1,a):
piles.append(piles[i-1]+data[i])
for j in xrange(b):
print bisect.bisect_left(piles,juicy[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 | import bisect
n = input()
worms = map(int, raw_input().split())
m = input()
query = map(int, raw_input().split())
wsum = [0] * n
for i in range(n):
if i == 0:
wsum[i] = worms[i]
else:
wsum[i] = wsum[i - 1] + worms[i]
for i in range(m):
print bisect.bisect_left(wsum, query[i]) + 1
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 1000001
s = 1
for i in range(n):
for j in range(a[i]):
cnt[s + j] = i + 1
s += a[i]
m = int(input())
b = list(map(int, input().split()))
for i in range (m):
print(cnt[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 n, m;
int main() {
int n;
scanf("%d", &n);
vector<int> v(n), sum(n);
int prev = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
sum[i] = v[i] + prev;
prev = sum[i];
}
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int temp;
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
public class worms {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = input()
l = map(int, raw_input().split())
m = input()
q = map(int, raw_input().split())
# n = 8089
# l = map(int, '1 6 3 1 1 2 4 1'.split())
# m = 11
# q = map(int, '14 8 12 1 10 6 15 16 19 3 18'.split())
z = [0]*m
for i in xrange(1, n):
l[i] += l[i-1]
bold_worms = sorted(enumerate(q), key=lambda x: x[1])
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class wormi{
public static PrintWriter out = new PrintWriter(System.out);//HACER FLUSHHHH
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
int cont =Integer.parseInt(lector.readLine());
S... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | N=int(raw_input().strip())
arr=raw_input().strip().split(' ')
ans=[0]
for i in xrange(N):
ans+=[i+1]*int(arr[i])
Q=int(raw_input().strip())
q=raw_input().strip().split(' ')
for i in q:
print ans[int(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 bisect
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
for i in range(1,n+1):
a[i]+=a[i-1]
q = int(input())
b = list(map(int,input().split()))
for i in range(q):
b[i]=bisect.bisect_left(a,b[i])
for i in range(q):
print(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 | n=int(input())
narr=list(map(int,input().split()))
rnge=[0]*10000001
p,i=1,1
for ii in range(n):
for j in range(narr[ii]):
rnge[i]=p
i+=1
p+=1
m=int(input())
marr=list(map(int,input().split()))
for i in range(m):
print(rnge[marr[i]]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #!/usr/bin/python3
import itertools as ittls
from collections import Counter
import re
def inputarray(func=int):
return map(func, input().split())
# ---------------------------------------
# --------------------------------------
n = int(input())
A = list(inputarray())
m = int(input())
B = inputarray()
W = [... | 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.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int []ar = new int[n];
for(int i=0;i<n;i++) {... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def read():
input()
sizes = list(map(int, input().split()))
input()
queries = list(map(int, input().split()))
return sizes, queries
def calc_indexes(sizes):
start_indexes = [1]
for i in range(len(sizes)):
start_indexes.append(start_indexes[i] + sizes[i])
return start_indexes
de... | 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())
w=list(map(int,input().split()))
q=int(input())
qarr=list(map(int,input().split()))
a=[]
ind=1
for i in w:
a+=[ind]*i
ind+=1
for i in qarr:
print(a[i-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
def search(starts, lo, hi, value):
while lo <= hi:
mid = (lo + hi) // 2
start = starts[mid]
if value < start:
hi = mid - 1
elif value > start:
lo = mid + 1
else:
return mid + 1
return lo
if __name__ == '__main__':
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class P {
public static void main(String... args) throws Exception {
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
int[] totals = new int[N];
StringTokenizer tok = new StringTokenize... | 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;
struct ii {
int l, r;
ii() {}
ii(int l, int r) : l(l), r(r) {}
} v[100100];
int n;
int bb(int val) {
int l = 0, r = n - 1, mid = 0;
while (l <= r) {
mid = (l + r) / 2;
if (val >= v[mid].l && val <= v[mid].r) break;
if (val < v[mid].l)
r = 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.util.*;
public class Solve {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
arr[0] = in.nextInt();
for (int i = 1; i < arr.length; i++) {
arr[i] = arr[i - 1] + in.nextInt();... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, i, a, b, j, x = 1, c, d[1000001];
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
for (j = x; j <= x + a - 1; j++) {
d[j] = i;
}
x = x + a;
}
cin >> b;
for (i = 1; i <= b; i++) {
cin >> a;
cout << d[a] << 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 = input()
a=map(int, raw_input().split())
m = input()
q = map(int, raw_input().split())
p = []
for i in xrange(n):
p += [i+1]*a[i]
for x in q:
print p[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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, sum = 0, i, j, ara[100000], mid, low, high;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &j);
sum += j;
ara[i] = sum;
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d", &k);
low = 0;
high = 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 | #include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0) ret += m;
return ret;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long exp(long long a, long long b, long long m) {
if (b == 0) return 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 | n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
am = [int(x) for x in input().split()]
lister = []
for i, x in enumerate(a):
lister += [i + 1] * x
for i in am:
print(lister[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 chk[1000002] = {0};
int g;
int main() {
int n;
cin >> n;
int a[n], suf[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
suf[0] = a[0];
int k = 1, d;
for (int j = 0; j < n; j++) {
for (int i = 0; i < a[j]; i++) chk[k++] = j + 1;
}
cin >> d;
... | 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()]
m = int(input())
q = [int(y) for y in input().split()]
l = []
for i in range(n):
l.append([i+1]*a[i])
f = []
for sub in l:
for e in sub:
f.append(e)
for i in range(m):
print(f[q[i]-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
def get_worm_pile(number):
for pile_number_minus_one, first_worm_number in enumerate(generated_positions):
if number < first_worm_number:
return pile_number_minus_one
return n
generated_positions ... | 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 as CS
def bin_search(val):
lo = 0
hi = n - 1
while (hi >= lo):
mid = lo + (hi - lo) // 2
if cs[mid] == val:
return mid
elif cs[mid] > val:
if cs[mid - 1] < val: return mid
hi = mid - 1
else:
if... | 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 Thu Oct 22 09:02:07 2020
@author: 章斯岚
"""
pile=[]
n=input()
a=map(int,input().split())
count=0
for i in a:
count+=1
pile.extend(i*[count])
m=input()
b=map(int,input().split())
for i in b:
print(pile[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 | # your code goes here
n1=int(input())
var=[int(x) for x in input().split()]
sumvar=sum(var)
li=list()
li.append(0)
index=0
arri=0
sumTillNow=var[0]
cnt=1
for index in range(1,sumvar+1):
if(index<=sumTillNow):
li.append(cnt)
else:
arri+=1
sumTillNow+=var[arri]
cnt+=1
li.append(cnt)
m=int(input())
var2=[int... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
def search(Max,new,num):
if new[0]>num:
return 1
Min =0
Mid = int((Max+Min)/2)
while Min<=Max:
if new[Mid]==num:
return Mid+1
break
elif new[Min]==num:
return Min+1
break
elif new[Mid]<num and new[Mid+1]>num:
return Mid+2
break
elif new[Mid]<num:
Min=Mid+1
else:
Max=M... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(input())
arr = [int(p) for p in input().split()]
juicyNo = int(input())
juicyArr = [int(p) for p in input().split()]
for i in range(1, len(arr)):
arr[i] += arr[i-1]
for i in range(len(juicyArr)):
index = bisect_left(arr, juicyArr[i])
print(index + 1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | a = int(input())
lista = list(map(int, input().split()))
b = int(input())
lista2 = list(map(int, input().split()))
worms = [0]
i = 1
for amt in lista:
worms += [i] * amt
i += 1
for worm in lista2:
print(worms[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 | import math
from bisect import bisect_left,bisect_right
def solve(m):
#just greater or equal
l=0
r=n-1
ans=-1
while(l<=r):
mid=l+(r-l)//2
if(pre[mid]>=m):
ans=mid
r=mid-1
else:
l=mid+1
print(ans+1)
n=int(input())
a=list(map(int,input()... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def buscaBinaria(lista, elemento):
inicio = 0
fim = len(lista) - 1
while (inicio <= fim):
meio = (inicio + fim) / 2
if elemento == lista[meio]:
return meio
elif (elemento < lista[meio] and meio == 0):
return meio
elif (elemento < lista[meio] and elemento > lista[meio-1]):
return meio
elif... | 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 m6(n, montos, n_jugs, jugs):
rangos_montos = []
suma = 0
for i in xrange(n):
suma += montos[i]
rangos_montos.append(suma)
sorted_jugs = sorted(jugs)
i = 0
j = 0
jugs_map = {}
while i < n_jugs and j < n:
if sorted_jugs[i] <= rangos_montos[j]:
... | PYTHON |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.