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 n, k;
const int sz = 1e6;
long long a[sz];
int main() {
cin >> n >> a[0];
for (int i = 1; i < n; i++) cin >> a[i], a[i] += a[i - 1];
int t, x, l = 0, h = n - 1, mid, res;
cin >> t;
while (t--) {
res = l = 0;
h = n - 1;
cin >> x;
while (l <= h) ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
cin >> m;
vector<long long int> b(m);
for (long long int i = 0; i < m; i++) cin >> b[i];
vector<long long int> c(n);
c[0] = a[0];
fo... | 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 long long MOD = 1000000007;
const int MAX = 2003;
class pile {
public:
long long first, last;
pile() { first = last = 0; }
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m, q, A;
cin >> n;
pile a[n + 1];
for (int i = 1; i <= 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 java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringToke... | 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=input()
s=s.split()
t=[1]
for i in range(n):
t.append(t[i]+int(s[i]))
t=sorted(t)
q=int(input())
a=input()
a=a.split()
for i in range(q):
p=bisect.bisect_left(t,int(a[i]))
if (int(a[i])==t[p]):
print(p+1)
else:
print(p)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
N = int(input())
A = list(map(int, input().split()))
M = int(input())
Q = list(map(int, input().split()))
now = 0
R = []
for a in A:
right = now + a
R.append(right)
now = right
for q in Q:
ind = bisect.bisect_left(R, q)
print(ind + 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 | length=input()
a=[]
last=0
summation=[]
def kanu(query):
low=0
high=length-1
middle=(high-low)/2
while low!=high and high-low!=1:
if(query==summation[middle]):
return middle+1
elif(query>summation[middle]):
low=middle
elif(query<summation[middle]):
... | 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 | nPiles = input()
nWormPile = input().split(' ')
nJuicyWorm = input()
labelJuicy = input().split(' ')
iWorms = []
idxPile = 0
for i in range(int(nPiles)):
idxPile += 1
for j in range(int(nWormPile[i])):
iWorms.append(idxPile)
for i in range(int(nJuicyWorm)):
print(iWorms[int(labelJuicy[i])-1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Zad474B {
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc = new FastReader();
int n = sc.nextInt();
StringBuilder answer = 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 | //package CodeforcesRoundN271;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
private static BufferedReader in;
private static StringTokenizer st;
public static void main(String[] args) throws IOException {
InputSt... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary_search(arr, key, start, end):
mid = start + (end-start)/2
if start > end:
return mid + 1
if arr[mid] == key:
return mid
elif arr[mid] > key:
return binary_search(arr, key, start=start, end = mid-1)
else:
return binary_search(arr, key, start=mid+1, end=end... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary(aim, start, end):
mid = (start + end) // 2
if a[mid] == aim:
return mid
if start >= end:
return end
if a[mid] > aim:
return binary(aim, start, mid - 1)
else:
return binary(aim, mid + 1, end)
inp = lambda : [*map(int, input().split())]
n = int(input())
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 | '''def find_indx(x) :
low=0
up=n-1
smaller=False
greater=False
while low<=up :
m=(low+up)/2
if x>s[m] :
if smaller==True :
return m+1
low=m+1
greater=True
elif x<s[m] :
if greater==True :
return m-1
up=m-1
smaller=True
else :
return m+1
return 1'''
n=int(input())
a=map(... | 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;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int[] which = new int[1000001];
int last = 0;
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 | #include <bits/stdc++.h>
using namespace std;
int n, m, x, a[100006], Ans[1000006];
inline void in(int &x) {
char c;
while (!isdigit((c = getchar())) && c ^ '-')
;
bool f = (c == '-');
if (f) (c = getchar());
for (x = 0; isdigit(c); (c = getchar())) x = x * 10 - 48 + c;
if (f) x = -x;
}
int main() {
i... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
piles = [int(x) for x in input().split()]
worms = int(input())
labels = [int(x) for x in input().split()]
L = []
k = 1
for x in range(len(piles)):
L.extend([k]*piles[x])
k += 1
for l in labels:
print(L[l-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;
const int N = 1000009;
int n, a[N] = {}, k = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int j = k; j < k + x; j++) a[j] = i;
k += x;
}
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
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 | import sys
def bin_search(plist, nu):
lo = 0
hi = len(plist) - 1
prober = ((lo + hi) / 2)
prev_prober = -1
while prober != prev_prober:
prev_prober = prober
if nu < plist[prober]:
hi = prober
elif nu > plist[prober]:
lo = prober
else:
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
w=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
pre=[w[0]]
for i in range(1,n):
pre.append(pre[i-1]+w[i])
for i in q:
left=0
right=n-1
ans=0
while(left<=right):
mid=left+(right-left)//2
if(pre[mid]>=i):
ans=mid
r... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.*;
/**
* Created by radoslav on 12/7/2014.
*/
public class B implements Runnable{
class TaskB{
int n;
int[] a;
int m;
int[] q;
int[] map = new int[1000000];
TaskB(int n,int[] a, int m, int[] q){
this.n = n;
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int upper(vector<int>& vec, int a) {
vector<int>::iterator uppers;
uppers = std::upper_bound(vec.begin(), vec.end(), a);
return uppers - vec.begin();
}
int main() {
int n;
cin >> n;
vector<int> vec;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
ve... | 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
n1=int(input())
a=[int(i) for i in input().split()]
n2=int(input())
c1=[int(i) for i in input().split()]
c=[]
c12=0
k12=0
lb=0
ub=n1
mid=(lb+ub)/2
for i in range(n1):
c12+=a[i]
c.append(c12)
#print(c)
for i in range(n2):
b=c1[i]
if b<c[0]:
print(1)
else:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
def solve(d, x):
return bisect.bisect_left(d, x)+1
n = int(raw_input())
a = map(int, raw_input().split())
m = int(raw_input())
q = map(int, raw_input().split())
d = [a[0]]
for i in range(1, len(a)):
d.append(d[i-1]+a[i])
for x in q:
print solve(d, x) | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
q = [int(i) for i in input().split()]
worm = []
for i in range(n):
for j in range(a[i]):
worm.append(i+1)
for i in range(m):
print(worm[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>
int b[1000010];
int main() {
int n, m, i, j, k;
int a;
while (~scanf("%d", &n)) {
j = 1;
for (i = 1; i <= n; i++) {
scanf("%d", &a);
while (a--) b[j++] = i;
}
scanf("%d", &m);
for (i = 1; i <= m; i++) {
scanf("%d", &k);
printf("%d\n", b[k]);
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
l=[int(i) for i in input().split()]
m=int(input())
a=[int(i) for i in input().split()]
sum=0
k=0
for i in range(n):
sum+=l[i]
l[i]=sum
#print(l)
for i in range(m):
x=bisect.bisect_left(l,a[i])
print(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 | L=[]
input()
r=1
for k in input().split():
L+=[r]*int(k)
r+=1
input()
for j in input().split():
print(L[int(j)-1])
# Made By Mostafa_Khaled | 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 bi_search(int a[], int n, int x) {
int fst = 0, lst = n - 1, mid;
while (fst <= lst) {
mid = (fst + lst) / 2;
if (a[mid] == x) return (mid + 1);
if (a[mid] > x)
lst = mid - 1;
else
fst = mid + 1;
}
return fst + 1;
}
void solve() {
i... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int bs(int b1, int b2, int temp, int n, int a[]) {
int mid = (b1 + b2) / 2;
if (mid == 0) {
return 1;
} else if (temp <= a[mid]) {
if (temp > a[mid - 1])
return mid + 1;
else
return bs(b1, mid, temp, n, a);
} else {
return bs(mid + 1, b2,... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
int main() {
int n, i, a[1000000], k, j = 1;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &k);
while (k--) {
a[j] = i + 1;
j++;
}
}
int m;
scanf("%d", &m);
while (m--) {
int g;
scanf("%d", &g);
printf("%d\n", a[g]);
}
return 0;
}
| CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long a[1000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long x;
a[0] = 0;
map<long long, long long> m;
for (int i = 1; i <= n; i++) {
cin >> x;
a[i] = x + a[i - 1];
}
long long j = 1;
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;
int arr[(int)1e5 + 1];
int q[(int)1e5 + 1];
int sol[(int)1e5 + 1];
int main() {
int n, m;
cin >> n;
cin >> arr[0];
for (int i = 1; i < n; i++) {
int x;
cin >> x;
arr[i] = arr[i - 1] + x;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> q[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 | def f():
n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))
A_2=[0]*len(A)
A_2[0]=A[0]
for i in range(1,len(A)):
A_2[i]=A_2[i-1]+A[i]
for i in range(len(B)):
left = -1
right = len(A)-1
while right > ... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int q[n], m, sum = 0;
q[0] = 0;
for (long long int i = 1; i <= n; i++) {
cin >> m;
q[i] = q[i - 1] + m;
sum += m;
}
long long int arr[sum + 1], index = 1;
for (long long int i = 1; i <= sum; 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 java.util.Scanner;
public class P474B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int p[]= new int[n];
int sum=1;
for(int i = 0 ; i<n ; i++)
{p[i]=in.nextInt(); sum+=p[i];}
int a[]= new int[sum];
int pile=1;
int j=1;
int r=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 | /**
* Created by mohammad on 8/27/16.
*/
import java.util.*;
public class Problem474B {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] worms = new int[n];
worms[0] = sc.nextInt();
for (int i = 1; i < n; i++)
... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
import java.io.*;
public class Main{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
public static int nextInt(){
try{
if(! st.hasMoreTokens()){
st = new StringTokenizer(br.readLine());
}
}catch(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;
long n, m, temp, p, q;
int main() {
cin >> n;
long a[n];
for (int i = 0; i < n; i++) {
cin >> p;
temp += p;
a[i] = temp;
}
cin >> m;
long b[m];
for (int i = 0; i < m; i++) {
cin >> p;
q = lower_bound(a, a + n, p) - a;
b[i] = q + 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=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
li=[0]
cur=1
s=0
for i in range(1,sum(a)+1):
if i>s+a[cur-1]:
s+=a[cur-1]
cur+=1
li.append(cur)
for i in q:
print(li[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 | 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 q:
print l[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;
int num[100007];
int main() {
vector<pair<int, int> > data;
int curr = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num[i];
data.push_back(make_pair(curr + 1, curr + num[i]));
curr = curr + num[i];
}
int m;
cin >> m;
int x;
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 | from bisect import bisect_left
n = int(input())
n1 = input().split()
lista = []
valor = 0
for e in n1:
valor += int(e)
lista.append(valor)
m = int(input())
m1 = input().split()
for e in m1:
print(bisect_left(lista, int(e)) + 1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int n;
cin >> n;
int inp, prev = 1;
int *table = (int *)malloc(sizeof(int) * 1000001);
for (long long i = 0; i < n; i++) {
cin >> inp;
for (int j = ... | 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 | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Asus
*/
import java.util.Scanner;
public class Chervi {
static int[] ans;
public static void main(Strin... | 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;
scanf("%d", &n);
long long location = 1;
long long a_aux;
int array[n][2];
for (int i = 0; i < n; i++) {
scanf("%d", &a_aux);
array[i][0] = location;
array[i][1] = a_aux + location - 1;
location += a_aux;
}
int m, start, e... | 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 = input().split()
k = 1
c = []
for elim in a:
for i in range(int(elim)):
c.append(k)
k += 1
m = int(input())
b =input().split()
for elim in b:
print(c[int(elim)-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()))
for i in range(1,n):
a[i]=a[i]+a[i-1]
c=(a[n-1]+1)*[0]
c[0]=1
for i in range(n):
c[a[i]]=1
for i in range(1,len(c)):
c[i]=c[i]+c[i-1]
m=int(input())
w=list(map(int,input().split()))
for i in w:
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 | import java.util.Scanner;
public class RENAMETHISBITCH {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int[] worms = new int[1000001];
int start = 0;
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
int pile = sc.nextInt();
for (int 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 | 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 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 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 binarysearch(a,m,n):
i=0
l=n-1
while(i<=l):
mid=(i+l)//2
if a[mid]==m:
return mid
#print(mid,'mid')
if m>=a[mid] and m<=a[mid+1]:
return mid+1
elif m>a[mid]:
i=mid+1
#print('i',i)
else:
l=mid-1
#print('l',l)
n=int(input())
s=0
a=[1]
for i in input().split():
s=s+int(i)
a.ap... | 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()))
m=int(input())
num=list(map(int,input().split()))
num2=sorted(num)
cnt=piles[0]
seq=1
dic={}
while num2:
if num2[0]<=cnt:
dic[num2[0]]=seq
del num2[0]
else:
cnt+=piles[seq]
seq+=1
for i in range(m):
print(dic[num[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 | t = input
p = print
r = range
n, a = int(t()), list(map(int, t().split()))
m, b = int(t()), list(map(int, t().split()))
f = [0]
for i in range(n):
f += [i + 1] * a[i]
for x in b:
p(f[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.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner ();
StringBuffer ans = new StringBuffer();
while (sc.hasNext(... | 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
input()
a = [0]
for x in map(int, input().split()):
a.append(a[-1] + x)
input()
for x in map(int, input().split()):
print(bisect.bisect_left(a, 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 | //package com.company;
import java.io.*;
import java.util.*;
public class Main {
static long TIME_START, TIME_END;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new FileInputStream("Test.in"));
PrintWriter pw... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.math.BigInteger;
import java.sql.Array;
import java.util.*;
import java.lang.*;
import java.util.Arrays;
public class geek {
public static void main(String[] args) {
try {
Scanner s = new Scanner(System.in);
StringBuffer sb=new StringBuffer();
int n=s.nextInt(... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
arr, res = [], 1
for i in list(map(int, input().split())):
arr += [res] * i
res += 1
m = int(input())
for j in list(map(int, input().split())):
print(arr[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 | ar=[0]
n=input()
p=list(map(int,raw_input().split()))
n=len(p)
for i in range(0,n):
for j in range(0,p[i]):
ar.append(i+1)
n=input()
an=map(int,raw_input().split())
for i in range(0,len(an)):
print ar[an[i]]
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # from sys import stdout
from bisect import bisect_left as bs
from math import log as lg
log = lambda *x: print(*x)
def cin(*fn, def_fn=str):
i,r = 0,[]
if fn: def_fn=fn[0]
for c in input().split(' '):
r+=[(fn[i] if len(fn)>i else def_fn) (c)]
i+=1
return r
####################################################
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
N=[int(i) for i in input().split()]
k=1
d={}
for i in range(n):
for j in range(N[i]):
d[k]=i+1
k+=1
m=int(input())
M=[int(i) for i in input().split()]
for i in range(m):
print(d[M[i]])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.Map;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author bitver
*/
public class Main {
public static void... | 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 worms2 {
public static void main(String[] args) {
int n,m,q;
int lo,hi,mid;
Scanner s = new Scanner(System.in);
n=s.nextInt();
int[]sum=new int[n];
sum[0]=s.nextInt();
for (int i=1;i<n;i++){
sum[i]=sum[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(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
sums = [a[0], ]
for x in range(1, n):
sums.append(sums[-1] + a[x])
sq = sorted(q)
d = dict()
start=0
for y in sq:
for x in range(start, n - 1):
# print (x,y)
if sums[x] >=y:
d[... | 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 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
*
* @author FZ
*/
public class Rnd271B {
Scanner in = new Scanner(System.in);
private Rnd271B() thr... | 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.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.Random;
import java.util.AbstractList;
import java.io.Writer;
import java.util.Map;
import java.util.List;
import java.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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import java.... | 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 binarySearch(value, xList):
low=0
high=len(xList)
while low!=high:
mid=(low+high)//2
if xList[mid]<=value:
low=mid+1
else:
high=mid
return low
n=int(input())
tmp=list(map(int,input().split()))
k=int(input())
ask=list(map(int,input().split()))
for 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 sys
n = int(sys.stdin.readline())
a = map(int, sys.stdin.readline().split())
m = int(sys.stdin.readline())
q = map(int, sys.stdin.readline().split())
def bin_find(arr, x):
position_begin = 0
position_end = len(arr) - 1
while position_begin != position_end:
position = (position_end + positi... | 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.*;
public class Worms{
public static void main(String[] args)throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
String[] temp = in.readLine().split(" ");
long[] a = new long[n];
long[][] list = new long[n][2]... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class Dia3 {
public static void problemaH() {
Scanner sc = new Scanner(System.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 | n,a,m,q=int(input()),list(map(int,input().split())),int(input()),list(map(int,input().split()))
l,f,j=[0],[],0
for i in range(n) :
l.append(l[i]+a[i])
for i in range(pow(10,6)) :
if j==len(l) :
break
if l[j]==i :
j+=1
f.append(j)
for i in q :
print(f[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
import java.util.Scanner;
public class aaa {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner k = new Scanner(System.in);
int m = k.nextInt();
int[] a = new int[m];
int[] comulative = new int[m];
a[0] = k.nextInt();
comulative[0] = a[0];
for (int i = 1; i < a.leng... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
int arr[1100000];
using namespace std;
int main() {
memset(arr, 0, sizeof arr);
int n;
cin >> n;
int x = 1, pre = 1;
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
arr[x] = i;
x += c;
}
x = arr[1];
for (int i = 1; i <= 1000000; i++) {
if (!arr[i])
arr[... | 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 Source {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] a = new int[n];
int total = 0;
for (int i = 0; i < n; i++) {
a[i] = scan.nextInt();
total += a[i];
}
int[] b = new int[total];
int w1 =... | 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 dp[1000000];
int main() {
int n;
cin >> n;
int arr[n];
int sum = 0;
int count = 1;
int k;
for (int i = 0; i < n; i++) cin >> k, sum += k, dp[i + 1] = sum;
int q;
cin >> q;
while (q--) {
int left = 0, right = n;
int a;
cin >> a;
while ... | 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;
vector<int> arr(n);
cin >> arr[0];
for (int i = 1; i < n; ++i) {
cin >> arr[i];
arr[i] += arr[i - 1];
}
sort(arr.begin(), arr.end());
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int a;
cin >> a;
cout <... | 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 binary_search(arr, low, high, target):
while low < high:
mid = low + int((high - low)/2)
if arr[mid] >= target:
high = mid
else:
low = mid + 1
return low + 1
def main():
n = int(input())
arr = [int(x) for x in input().split()]
m = int(input())
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import atexit
import io
import sys
buff = io.BytesIO()
sys.stdout = buff
@atexit.register
def write():
sys.__stdout__.write(buff.getvalue())
def binsearch(arr,elem):
first=0
last=len(arr)-1
while first<=last:
mid=(first+last)//2
if elem>arr[mid-1] and elem<=arr[mid]:
break... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.util.*;
public class A
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
a[0]=s.nextInt();
for(int i=1;i<n;i++)
a[i]=a[i-1]+s.nextInt();
int m=s.nextInt();
for(int... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=int(input())
l=[int(i) for i in input().split()]
m=int(input())
k=[int(i) for i in input().split()]
psa=[]
s=0
for i in range(len(l)):
s+=l[i]
psa.append(s)
for i in k:
t=bisect.bisect_left(psa,i)
print(t+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #!/usr/bin/env python3
import atexit
import io
import sys
import bisect
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B
@atexit.register
def write():
sys.__stdout__.write(_O_B.getvalue())
def main():
n=int(input())
a=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 | #include <bits/stdc++.h>
using namespace std;
long long int a[1000001];
int main() {
long long int n;
cin >> n;
int _count = 1;
for (int i = 0; i < n; i++) {
long long int x;
cin >> x;
for (int j = 0; j < x; j++) {
a[_count++] = i;
}
}
long long int x;
cin >> x;
while (x--) {
l... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def binary_search(data, n, value):
mid = n // 2
low = 0
high = n - 1
while True:
if value <= data[mid] and value > data[mid - 1]:
return mid
if value > data[mid]:
low = mid + 1
else:
high = mid - 1
mid = (high + low) // 2
n = int(input())
data = list(map(int, input().split()))
summ_arr = []
summ... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n=input()
a=[int(x) for x in input().split()]
m=input()
q=[int(x) for x in input().split()]
for i in range(1,len(a)):
a[i]+=a[i-1]
for x in q:
print(bisect.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 | #474B-Worms
n=int(input())
alist=[int(x) for x in input().split(' ')]
for i in range(1,n):
alist[i]+=alist[i-1]
m=int(input())
qlist=[int(x) for x in input().split(' ')]
for i in range(m):
min0=0
max0=n-1
q=qlist[i]
if q <= alist[0]:
print(1)
else:
while max0-min0 > 1:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect
n = int(raw_input())
a = map(int, raw_input().split())
b = [1]
c = 1
for i in a:
c += i
b.append(c)
raw_input()
for i in map(int, raw_input().split()):
print bisect(b, i) | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
int m;
cin >> m;
vector<long long 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=[0 for i in range(1000001)]
n=int(input())
L=list(map(int,input().split()))
j=0
for i in L:
N[i+j]=1
j=i+j
P=[N[0]]
for i in range(1,1000001):
P.append(P[i-1]+N[i])
k=int(input())
M=list(map(int,input().split()))
for i in range(k):
print(P[M[i]-1]+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int> > quest(100006, vector<int>(2));
int n, i, a[100006], m, num, ans[100006], j = 0, sum = 0;
cin >> n;
for (i = 0; i < n; ++i) cin >> a[i];
cin >> m;
for (i = 0; i < m; ++i) {
cin >> num;
quest[i][0] = num;
quest[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 | def binary_search(alist, item, n):
first = 0
last = n - 1
found = False
while first <= last and not found:
midpoint = (first + last)//2
#print "First = " + str(first) + " | " + "Mid = " + str(midpoint) + " | " + "Last = " + str(last) + " | Search: " + str(item)
if alist[midpoint] == item:
found = True
r... | 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 |
get_int = lambda: map(int, input().split())
heaps_quantity = get_int()
heap_capacity = get_int()
worms_quantity = get_int()
worm_number = get_int()
a = 0
cnt = 0
h = []
for i in heap_capacity:
a += i
cnt += 1
for j in range(a - i, a):
h.append(cnt)
for i in worm_number:
print(h[i-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100050], m, q, in = 0;
map<int, int> b;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 1; i < n; ++i) a[i] += a[i - 1];
for (int i = 0; i < a[n - 1] + 1; ++i) {
if (i > a[in]) ++in;
b[i] = in + 1;
}
cin >> m;
... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(raw_input())
a= map(int,raw_input().split())
m=int(raw_input())
q= map(int,raw_input().split())
accu=0
for i in xrange(n):
accu+=a[i]
a[i]=accu
# for qi in q:
# print bisect.bisect_left(a,qi)+1
def busquedaBinaria(a,inicio,fin,elemento):
centro=(inicio+fin)/2
if inicio==fin:... | 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 |
li=[]
m=int(input())
a=1
for i in input().split():
li+=[a]*int(i)
a+=1
n=int(input())
for j in input().split():
print(li[int(j)-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
int arr[n];
for (int &i : arr) cin >> i;
for (long long int i = (1); i < (n); i++) {
arr[i] += arr[i - 1];
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
int ans = lower_b... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100005];
int n, q, x = 1, b[100005], h;
int find(int k) {
int l = 0, r = n - 1;
while (l <= r) {
h++;
int m = (l + r) / 2;
if ((a[m].first == k) || (a[m].second == k) ||
(a[m].first < k && a[m].second > k))
return m;
if (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 | input = raw_input
n = int( input() )
a = [int(x) for x in input().split()]
m = int( input() )
q = [int(x) for x in input().split()]
for i in xrange( 1, n ):
a[i] = a[i-1] + a[i]
def fnd(a,z):
lo = 0
hi = n
while lo < hi:
mid = (hi + lo) // 2
if z > a[mid]:
lo = mid ... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
arr = list(map(int, input().split()))
q = int(input())
qrs = list(map(int, input().split()))
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i - 1]
for qr in qrs:
left = 0
right = len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == qr or 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 n, m, a[100000], k, l, r, c, i;
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> a[0];
for (i = 1; i < n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
cin >> m;
while (m--) {
cin >> k;
l = 0;
r = n - 1;
w... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.