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 |
|---|---|---|---|---|---|
451_C. Predict Outcome of the Game | There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each... | 2 | 9 | #include <bits/stdc++.h>
long long t, n, k, d1, d2;
int slove(long long d1, long long d2) {
long long s1, s, x1, x2, x3;
s1 = d1 + d2;
s = s1 + d2;
x1 = x2 = x3 = (k - s) / 3;
x1 += s1;
x2 += d2;
if ((n % 3) != 0 || (k - s) % 3 != 0 || (x1 < 0) || (x3 < 0) || (x2 < 0) ||
x1 > (n / 3) || x2 > (n / 3)... | CPP |
451_C. Predict Outcome of the Game | There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
bool ok(long long n1, long long n, long long d1, long long d2) {
long long sum;
sum = d1 + d2;
if (sum <= n1 && !((n1 - sum) % 3)) {
sum = max(d1, d2) + abs(d1 - d2);
if (sum <= n && !((n - sum) % 3)) return 1;
}
sum = max(d1, d2) + abs(d1 - d2);
if (sum... | CPP |
451_C. Predict Outcome of the Game | There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, k, d1, d2;
cin >> n >> k >> d1 >> d2;
int i, j;
bool ans = false;
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
long long w = k + i * d1 + (1 - i) * (-d1) + j * d2 + (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>
int main() {
int n;
scanf("%d", &n);
int ar[n + 1];
for (int i = 1; i <= n; i++) scanf("%d", &ar[i]);
int q;
ar[0] = 0;
scanf("%d", &q);
int arr[q];
for (int i = 0; i < q; i++) scanf("%d", &arr[i]);
for (int i = 2; i <= n; i++) ar[i] += ar[i - 1];
int mid, st, fi;
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 | # #
# CodeForces
# Problem 474B
# Python 2.7
# #
# Number of heaps
n = int(raw_input())
# Heaps
# Input and put them in a row
a = []
i=1
for heap in raw_input().split():
for j in range(int(heap)):
a.append(i)
i += 1
# Delicious worms
m = int(raw_input())
# Worms' numbers
q = map(int, raw_input().spli... | 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 busca_binaria(lista, numero):
comeco = 0
fim = len(lista)
aux = 0
while True:
meio = (comeco + fim) / 2
if comeco > fim:
break
if lista[meio] == numero:
return meio + 1
elif lista[meio] < numero:
comeco = meio + 1
elif lista... | 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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Unsupported... | 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 size;
cin >> size;
int arr[1000001] = {};
for (int i = 1; i <= size; i++) cin >> arr[i];
for (int i = 1; i <= size; i++) arr[i] += arr[i - 1];
cout << endl;
int q;
cin >> q;
while (q--) {
int n;
int ans;
cin >> n;
int l = 1... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(input())
n1 = input().split()
m = int(input())
m1 = input().split()
lista = []
valor = 0
for e in n1:
valor += int(e)
lista.append(valor)
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 | from sys import stdin, stdout
def get_inter(piles, n):
res = [(1, piles[0])]
s = piles[0]
for i in range(1, n):
s += piles[i]
res.append((res[i-1][1]+1, s))
return res
def binarySearch(arr, l, r, x):
while l <= r:
mid = l + (r - l)//2
# Check if x is present at 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 Binary(x,l,Min,Max):
## b = (Max + Min)/2
## if Min+1 >= Max:
## return Min
## else:
## if x <= l[b] and x > l[b-1]:
## return b
## else:
## if x > l[b]:
## Min += (b+1)
## return Binary(x,l,Min,Max)
## 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 | #include <bits/stdc++.h>
using namespace std;
long long int a[1111111];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
for (long long int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
long long int m;
cin >> m;
while (m--) {
long 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 bins(lis,el,num):
left=0
right=num-1
while right>left:
mid=(left+right)/2
if el>lis[mid]:
left=mid+1
else:
right=mid
return left
n=input()
a=map(int,raw_input().split())
m=input()
q=map(int,raw_input().split())
total=0
totalist=[]
for k in xrange(n):
... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def bsearch(arr, start, end, x):
m = 0
while start < end:
m = (start + end) // 2
if arr[m] == x:
return m + 1
if arr[m] < x:
start = m + 1
else:
end = m
assert start == end
return start + 1
n = int( input().strip() )
a = list( map( in... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | def get_ans(a,num):
l,r = 0,len(num)-1
while(r-l>1):
mid = l + (r-l)/2
if(num[mid]==a): return mid
elif(num[mid] < a): l = mid
else: r = mid-1
if(num[r] < a): return r+1
if(num[l]>=a): return l
else: return r
t = input()
num = map(int, raw_input().split())
for i in range(1,t):
num[i] = num... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long n, m, r, j, k = 1, n1, m1, d, l, a[100007], b[100009];
double e;
string s[1004];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
cin >> m;
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < m; i++... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=[int(x) for x in input().split()]
m=int(input())
q=[int(x) for x in input().split()]
s=1
W=[0]*(10**6+1)
for i in range (n):
W[s:s+a[i]]=[i+1]*a[i]
s+=a[i]
for i in q:
print(W[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())
l=list(map(int,input().split()))
ju=int(input())
p=list(map(int,input().split()))
for i in range(1,n):
l[i]+=l[i-1]
l.insert(0,0)
for i in p:
f=0
r=n
while(r>=f):
mid=(f+r)//2
if l[mid]==i or(i<l[mid] and i>l[mid-1]):
print(mid)
break
elif l... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import fileinput, math
### ###
# utility func #
### ###
dbug = True
def stoi(s):
return([ int(x) for x in s.split() ])
def pd(s, label=''):
global dbug
if dbug:
header = 'debug:'
if label != '':
header += ' (%s)\t' % label
print header, s
def perm(n, k, wheels=True):
if wheels:
ass... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
long long int res = 1;
a %= 1000000007;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
long long int modInverse(long long int 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 |
def main():
n = int(input())
tab = list(map(int,input().split()))
couples = [tab[0]]
for x in range(1,n):
couples.append(tab[x]+couples[x-1])
q = int(input())
qtab = list(map(int,input().split()))
iqtab = []
for x in range(q):
iqtab.append([x,qtab[x]])
iqtab.sort(key = lambda x: x[1])
current_s = 0
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
class TC {
public:
void solve() {
long long int i, n;
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
if (i > 0) {
a[i] += a[i - 1];
}
}
long long int m;
cin >> m;
long long int b[m], j = 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 | n=int(input())
a=[int(i) for i in input().split()]
m=int(input())
c=0
q=[int(i) for i in input().split()]
for i in range(0,n):
a[i]=a[i]+c
c=a[i]
for i in range(0,m):
l=0
u=n-1
while((u-l)>0):
mid=(int)((l+u)/2)
if(q[i]>a[mid-1] and q[i]<=a[mid]):
print(mid+1)
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m;
int a[maxn];
int ans[1000005];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
a[i] += a[i - 1];
}
int cnt = 0;
for (int i = 0; i <= a[n - 1]; i++) {
if (i > a[cnt... | 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 maxn = 100010;
int a[maxn];
int binarySearch(int arr[], int l, int r, int x) {
if (r >= l) {
int mid = l + (r - l) / 2;
if (arr[mid] >= x && arr[mid - 1] < x) return mid;
if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
return binarySea... | 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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
public class p474B {
public static void main(String[] args) throws IOExc... | 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())
L = [int(x) for x in raw_input().split()]
m = int(raw_input())
queries = [int(x) for x in raw_input().split()]
def binary_search(L, lo, hi, needle):
#print L
while lo <= hi:
if lo == hi: return hi
if lo + 1 == hi:
if needle <= L[hi] and needle > L... | 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
from bisect import bisect_left
n=int(input())
l=list(map(int,stdin.readline().split()))
m=int(input())
q=list(map(int,stdin.readline().split()))
c=0
l1=[]
for i in l:
c+=i
l1.append(c)
for i in q:
print(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(raw_input())
v = map(int, raw_input().split())
m=int(raw_input())
qs = map(int, raw_input().split())
d=[0]*1000005
i=1
for (px,x) in enumerate(v):
for y in range(x):
d[i]=px+1
i+=1
for q in qs:
print d[q] | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | '''
import time
import random
n = 100000
seq = range(1000)
a = []
for i in range(n):
a.append(random.choice(seq))
m = 1000
seq = range(10000000)
q = []
for i in range(m):
q.append(random.choice(seq))
'''
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = 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;
const int N = 1e5 + 10;
int n, s[N];
int q, x;
int BS(int x) {
int l = 1, r = n, kq = 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (s[mid] >= x)
kq = mid, r = --mid;
else
l = ++mid;
}
return kq;
}
int main() {
cin >> n;
for (int 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 | #include <bits/stdc++.h>
using namespace std;
int a[101000];
int b[1000100];
vector<pair<int, int> > vx;
vector<pair<pair<int, int>, int> > vz;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int c = 0;
int q = 0;
for (int i = 0; i < n; i++) {
q++;
for (int j = c + 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 maxn = 1e5 + 5;
pair<int, int> a[maxn];
struct node {
int q, ans, id;
} b[maxn];
int main() {
int n, m;
scanf("%d", &n);
int last = 1;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[i] = {last, last + x - 1};
last += x;
}
sc... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
a = int(input())
piles = list(map(int, input().split()))
b = input()
worms = list(map(int, input().split()))
for i in range(1, a):
piles[i] = piles[i] + piles[i - 1]
for worm in worms:
print(bisect.bisect_left(piles, worm) + 1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
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
Mid = int((Ma... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import sys
def pyes_no(condition) :
if condition :
print "YES"
else :
print "NO"
def plist(a, s = ' ') :
print s.join(map(str, a))
def rint() :
return int(sys.stdin.readline())
def rints() :
return map(int, sys.stdin.readline().split())
def rfield(n, m = None) :
if m == None :
m = n
fi... | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(raw_input())
x = list(map(int,raw_input().split()))
a = [0]
s = 0
for i in x:
s += i
a.append(s)
def binary_search(x):
low = 0
high = n
mid = (high+low)/2
while(low<=high):
mid = (high+low)/2
if (high-low) == 1:
if a[low] != x:
return high
else:
return low
else:
if a[mid] == 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Worms {
static class RealScanner {
BufferedReader br = new BufferedReader(new InputStr... | 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(arr, ele):
l = 0
r = len(arr)
curr = (l+r)//2
while True:
if arr[curr][0] <= ele <= arr[curr][1]:
return curr+1
else:
if arr[curr][1] > ele:
r = curr
else:
l = curr
curr = (l+r)//2
n = 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 | n = int(input())
s = 0
prev_s = 0
m = []
pile_num = 1
for x in input().split():
s += int(x)
for i in range(prev_s, s):
m.append(pile_num)
prev_s = s
pile_num += 1
q = int(input())
for x in input().split():
print(m[int(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 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
l = []
for i in range(n):
l += [i+1]*a[i]
for i in range(m):
print(l[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 m, n;
cin >> n;
int a[n], i;
for (i = 0; i < n; ++i) {
cin >> a[i];
if (i != 0) a[i] += a[i - 1];
}
cin >> m;
int b[m];
for (i = 0; i < m; ++i) cin >> b[i];
for (i = 0; i < m; ++i) {
int beg = 0;
int end = n - 1;
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 | import bisect
def search(starts, lo, hi, value):
return bisect.bisect(starts, value)
if __name__ == '__main__':
n = int(input())
sizes = [int(x) for x in input().split()]
starts = []
for i, size in enumerate(sizes):
start = 1 if not starts else starts[i - 1] + sizes[i - 1]
star... | 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
from bisect import bisect_left
n = int(input())
A = list(map(int, input().split()))
m = int(input())
Q = list(map(int, input().split()))
sum_A = list(A)
for i in range(1, n):
sum_A[i] += sum_A[i-1]
for q in Q:
print(bisect_left(sum_A, q) + 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 bb(const int array[], int q, int l) {
int first = 0;
int last = l - 1;
int pivote;
while (first <= last) {
pivote = (first + last) / 2;
if (array[pivote] >= q) {
if (pivote == 0) {
return pivote + 1;
} else if (pivote > 0 && array[piv... | 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;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
long long int m;
cin >> m;
long long int q[m];
for (long long int i = 0; i < m; i++) cin >> q[i];
vector<pair<long long int, long long int>> vec;... | 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()))
temp=0
for i in range(n):
temp+=a[i]
a[i]=temp
b=[0]*(a[-1]+1)
p1=0
for i in range(1,a[-1]+1):
if i>a[p1]:p1+=1
b[i]=p1+1
for i in 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class worms {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer line = 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 | __author__ = 'Rajan'
n = int(input())
# precalculate
pre = [0 for i in range(1000000+10)]
mp = map(int,input().split())
j = 0
index = 1
for k in mp:
for i in range(j+1,j+k+1):
pre[i]= index
index+=1
j+=k
m = int(input())
mp = map(int,input().split())
for k in mp:
print(pre[k])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args){
FastScanner sc = new FastScanner();
int n = sc.nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int m = sc.nextInt();
Worm[] worms = new Worm[m];
fo... | 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.Arrays;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Solve {
public stat... | JAVA |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | import bisect
n = int(raw_input())
p = map(int,raw_input().split())
m = int(raw_input())
q = map(int,raw_input().split())
a = [0]*(n+1)
for i in range(n):
a[i+1] = a[i] + p[i]
ans = [0]*m
for i in range(m):
ans[i] = bisect.bisect_left(a,q[i])
for i in ans:
print 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 | v = []
n = int(input())
a = map(int, input().split())
r=1
for k in a:
v+=[r]*k
r+=1
m = int(input())
q = map(int, input().split())
for j in q:
print(v[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() {
int n, m, i, x;
vector<int> a;
vector<int>::iterator it;
scanf("%d", &n);
scanf("%d", &x);
a.push_back(x);
for (i = 1; i < n; i++) {
scanf("%d", &x);
a.push_back(x + a[i - 1]);
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("... | 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;
scanf("%d", &n);
int a[n], i, sum = 0, st = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int m, k, p;
scanf("%d", &m);
int b[m], j, h;
for (j = 0; j < m; j++) {
scanf("%d", &b[j]);
}
for (i = 0; i < n; i++) sum = sum + a[i];
int ans[sum]... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, elm, m;
cin >> n;
int prefixsum = 0;
for (int i = 0; i < n; ++i) {
cin >> elm;
prefixsum += elm;
v.push_back(prefixsum);
}
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> elm;
int ans = lower_bound(v.begin(... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left as lbis
n = int(input())
ls = list(map(int, input().split()))
bis = [0]
for i in ls:
bis.append(bis[-1]+i)
bis = bis[1:]
ls = bis
m = int(input())
ls = list(map(int, input().split()))
for i in ls:
print(lbis(bis, 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 | # cf271B
import sys
import bisect
sys.setrecursionlimit( 10 **5 )
# sys.stdin = open("input.txt", 'r')
# sys.stdout = open("output.txt", 'w')
readline = sys.stdin.readline
def process():
n = int(readline())
arr, tmp = [], 0
tmp_list = list(map(int, readline().strip().split()))
for i in tmp_list:
... | 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
import bisect
num_piles = int(raw_input())
piles = map(int, raw_input().split())
num_worms = int(raw_input())
labels = map(int, raw_input().split())
accu=0
for i in xrange(num_piles):
accu+=piles[i]
piles[i]=accu
for label in labels:
print bisect.bisect_left(piles, label) + 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 = int(input())
ps = list(map(int, input().split()))
m = int(input())
qs = list(map(int, input().split()))
rs = [0]
for p in ps:
rs.append(rs[-1] + p)
for q in qs:
print(bisect.bisect_left(rs, 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 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
d=[0]
for i in range(n):
d.append(d[i]+a[i])
d.append(1000001)
for i in range(m):
start=0;end=len(d)-1
while start<end:
k=(start+end)//2
if q[i]<d[k]:
end=k-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 | #include <bits/stdc++.h>
using namespace std;
int cal(int* a, int n, int t) {
int low = 1, high = n, mid = 0;
while (low < high) {
mid = (high + low) / 2;
if (a[mid] < t) {
low = mid + 1;
mid = (high + low) / 2;
if (low >= high) {
if (a[mid] <= t)
return mid;
else... | 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()))
b = []
j = 1
for i in a:
while i != 0:
b.append(j)
i -= 1
j += 1
for i in q:
print(b[i - 1]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
a=[int(x) for x in input().split()]
m=int(input())
l=[int(y) for y in input().split()]
ans=[]
k=0
for i in range(n):
ans+=[i+1]*a[i]
for i in range(m):
print(ans[l[i]-1])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
sumi=0
a=list(map(int,input().split()))
for i in range(n):
sumi+=a[i]
a[i]=sumi
m=int(input())
q=list(map(int,input().split()))
for p in q:
start=0
end=n-1
while True:
k=(start+end)//2
if a[k]==p:
ans=k
break
elif end-start<1:
ans=start
break
elif a[k]>p:
end=k
else:
star... | 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 | arr = []
leng = 0
def find(value):
low = 0
high = leng - 1
while high - low != 0:
med = int((low + high) / 2)
if value > arr[med]:
low = med
else:
high = med
if high - low == 1:
if value <= arr[low]:
return low + 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()))
qq = sorted(q)
ans = dict()
limit = 0
i = 0
for k in qq:
while not (limit < k <= limit + a[i]):
limit += a[i]
i += 1
ans[k] = i + 1
for k in q:
print(ans[k])
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n,a = input(),map(int,raw_input().split())
m,b = input(),map(int,raw_input().split())
f = [0]
for i in range(n): f += [i+1]*a[i]
for x in b: print f[x]
| PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | arr = []
k = 1
n = int(input())
tmp = list(map(int, input().split()))
for i in range(n):
arr += [k] * tmp[i]
k += 1
m = int(input())
tmp = list(map(int, input().split()))
for i in range(m):
print(arr[tmp[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,line=int(input()),map(int,raw_input().split())
m,worms=int(input()),map(int,raw_input().split())
maptable=[]
for i in range(1,n+1):
maptable+=[i]*line[i-1]
#print maptable
for i in range(0,m):
print maptable[worms[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;
pair<int, int> p[1000006];
int main() {
int n, x = 0, a, m, q;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
p[i].first = x + 1;
p[i].second = x + a;
x = p[i].second;
}
cin >> m;
while (m--) {
cin >> q;
int 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 | def binary(arr, k, lo = 0):
hi = len(arr)
while(lo < hi):
mid = (lo + hi)//2
if arr[mid] < k:
lo = mid + 1
else:
hi = mid
return lo
## taking input
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
## ma... | 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 = [0]
for i in raw_input().split():
a.append(a[-1] + int(i))
m = input()
d = map(int, raw_input().split())
for i in d:
print bisect.bisect_left(a, i) | PYTHON |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int pos[100010];
pos[0] = 0;
for (int i = 0; i < n; i++) {
int buf;
cin >> buf;
pos[i + 1] = pos[i] + buf;
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int worm;
cin >> worm;
int ans = lower_bound(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 | #include <bits/stdc++.h>
using namespace std;
const long long mxn = 1e5 + 7;
int main() {
int n, a[mxn], q, l[mxn], r[mxn], x;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (i == 1) {
l[i] = 1;
r[i] = a[i];
} else {
l[i] = r[i - 1] + 1;... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # https://codeforces.com/problemset/problem/474/B
import bisect
n = int(input())
arr = [0]
for x in input().split():
arr.append(arr[-1]+int(x))
q = int(input())
queries = [int(x) for x in input().split()]
for x in queries:
pos = bisect.bisect_left(arr,x)
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 | import bisect
n=int(input())
a=list(map(int,input().split()))
c=[]
s=0
for i in range(n):
c.append(s+a[i])
s=s+a[i]
#c.append(max(c)+1)
#print(c)
m=int(input())
a=list(map(int,input().split()))
for i in range(len(a)):
print(bisect.bisect_left(c,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 | n = int(input())
a = input().split(' ')
s = [int(a[0])]
for i in range(1, n):
s.append(s[i - 1] + int(a[i]))
m = int(input())
q = list(map(int, input().split(' ')))
q = list(zip(q, range(m)))
q.sort()
q.append((1000001, m))
j = 0
ans = [0] * m
for i in range(n):
while s[i] >= q[j][0]:
ans[q[j][1]] = 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())
arr=list(map(int,input().split()))
n,m=map(int,input().split())
t=sys.stdin.buffer.readline()
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
sys.stdout.write("Yes" + '\n')
s="abcdefghijklmnopqrstuvwxyz'''
import bisect
n=int(input())
arr=list(map(int,input().split()))
pile=[0]*n
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 |
// * * * its fun to do the impossible * * * //
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Worms {
static class Pair implements Comparable<Pair>{
int a;
int b;
Pair(int a , int b){
... | 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())
b = []
a = list(map(int, input().split()))
r = 1
for k in a:
b += [r]*int(k)
r += 1
m = int(input())
x = list(map(int, input().split()))
for i in x:
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 | #!/usr/bin/env python3
# 00:45 start
import bisect
n = input()
worms = [0]
for w in map(int, input().split()):
worms.append(worms[-1] + w)
nq = input()
for q in map(int, input().split()):
print(bisect.bisect_left(worms, 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;
const int maxsize = 1e5 + 3, maxint = 0X3f3f3f3f;
double error = 1e-6;
int n, m;
long long arr[maxsize];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
arr[i] = x + arr[i - 1];
}
scanf("%d", &m);
for (int i = 0; i ... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import bisect_left
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
for i in range(1,n):
a[i] = a[i] + a[i-1]
for i in range(m):
pos = bisect_left(a, q[i])
print(pos+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())
l=list(map(int,input().split()))
t=int(input())
for i in range(1,n):
l[i]=l[i-1]+l[i]
x=list(map(int,input().split()))
for i in x:
print(bisect.bisect_left(l,i)+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
p = dict()
k = 1
for i in range(n):
for j in range(c[i]):
p[k + j] = i + 1
k += c[i]
m = input()
c = list(map(int, input().split()))
for i in c:
print(p[i]) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | from bisect import *
n=int(input())
l=list(map(int,input().split()))
m=int(input())
d=list(map(int,input().split()))
for i in range(1,n):
l[i]+=l[i-1]
for i in d:
print(bisect_left(l,i)+1)
| PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n = int(input())
piles = list(map(int, input().split()))[:n]
juicy_number = int(input())
juicy = list(map(int, input().split()))[:juicy_number]
worms = [piles[0]]
j = 0
for i in range(1, len(piles)):
number_two = worms[j] + piles[i]
worms.append(number_two)
j += 1
def binarySearch(arr, l, r, x):
whi... | 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 M[100005];
int main() {
ios::sync_with_stdio(0);
long long n, j, a;
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> M[i];
M[i] += M[i - 1];
}
cin >> j;
for (long long i = 0; i < j; i++) {
cin >> a;
long long l = 1;
long long... | CPP |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 |
from collections import deque
import bisect
n = int(input())
l1 = list(map(int,input().split()))
a = deque()
a.append([1 , l1[0]])
b = deque()
b.append(l1[0])
for i in range(1 , n):
x = a[-1][1] + 1
y = a[-1][1] + l1[i]
a.append([x , y])
b.append(y)
#print(a)
b = sorted(b)
#print(b)
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, p, nj, j;
cin >> n;
int sum[n];
for (int i = 0; i < n; i++) {
cin >> p;
if (i == 0) {
sum[i] = p;
} else {
sum[i] = p + sum[i - 1];
}
}
cin >> nj;
int u;
for (int k = 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 | if __name__ == "__main__":
n = int(input())
list1 = list(map(int,input().split()))
m = int(input())
list2 = list(map(int,input().split()))
def find(data,k):
i,j = 0, len(data)
while i < j:
m = (i+j)//2
if data[m]>=k:
j = m
else:
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | n=int(input())
l=[int(i) for i in input().split()]
psum=[0]*n
psum[0]=l[0]
for i in range(1,n):
psum[i]=psum[i-1]+l[i]
from bisect import bisect_left
q=int(input())
qarry=[int(i) for i in input().split()]
for i in qarry:
print(bisect_left(psum,i)+1) | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | input()
d={}
k=1
m=1
for i in map(int,input().split()):
for j in range(i):
d[k]=m
k+=1
m+=1
input()
for i in map(int,input().split()):
print(d[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 | # coding =utf-8
n = int(input())
a = map(int,raw_input().split())
m = int(input())
q = map(int,raw_input().split())
t = []
for i in range(a[0]):
t.append(1)
for i in range(1,n):
a[i]+=a[i-1]
for j in range(a[i-1],a[i]):
t.append(i+1)
for i in q:
print t[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>
int c[1000000];
int main() {
int n, a[100005], b[100005], i, m, k = 1, j, x = 0, l = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
for (j = 0; j < a[i]; j++) c[l++] = k;
k++;
}
scanf("%d", &m);
for (i = 0; i < m; i++) scanf("%d", &b[i]);
for (i = 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 | n = int(input())
L = list(map(int, input().split()))
for i in range(1,n):
L[i] += L[i-1]
a = [0]*(L[n-1]+1)
for i in L:
a[i] = 1
for i in range(1,L[n-1]+1):
a[i] += a[i-1]
for i in range(1,L[n-1]+1):
a[i] += 1
for i in L:
a[i] -= 1
q = int(input())
Q = list(map(int, input().split()))
for i in ra... | 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 binsearch(a, m):
low = 0
high = len(a)-1
while low<high:
mid = (low+high)//2
if a[mid]<m:
if low!=mid:
low = mid
else:
return high
elif a[mid]>m:
high = mid
elif a[mid]==m:
return mid
... | PYTHON3 |
474_B. Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 2 | 8 | # Codeforces Round #271 (Div. 2)
# http://codeforces.com/problemset/problem/474/B
n = int(raw_input())
a = map(int, raw_input().split(" "))
s = [0]*(n+1)
# s[i] is the largest in set i
for i in range(1, n + 1):
s[i] = s[i - 1] + a[i - 1]
def label(num):
low = 1
high = n
while True:
if (low == ... | 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 | '''
Created on Nov 16, 2014
@author: czx
'''
n=int(input())
s=map(int,raw_input().split())
w=[0 for x in range(1000001)]
k=0
for i in range(n):
for j in range(k+1,k+s[i]+1):
w[j]=i+1
k=k+s[i]
m=int(input())
s=map(int,raw_input().split())
for i in range(m):
print w[s[i]] | PYTHON |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.