solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>... | 12 | CPP |
#include <bits/stdc++.h>
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define len(a) (int) (a).size()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define int long long
using namespace std;
void solve();
mt19937 rnd(2007);
signed main(){
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freope... | 12 | CPP |
/*
构造一个正交化的线性基
实现完全正交 is impossible;
退而求之局部正交,即crucial musk不能出现在其他向量中
竟然要用并查集我日你先人(
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define pb push_back
const int ha = 1e9+7;
inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline void ADD(int &x,int y){ x+=y; if(... | 12 | CPP |
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
#define f first
#define s second
#define nl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vec... | 12 | CPP |
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 500000;
const long long modd = 1000000007;
int n, m;
int kk;
int aa[N + 5];
long long anss[N + 5], co = 0;
int ff[N + 5];
struct ab
{
int u;
int v;
} ee[N + 5];
long long qpow(long long a, long long b)... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
ll inf = 4e18, mod = 1e9 + 7;
inline ll power(ll x, ll n, ll m = LLONG_MAX)
{
ll res = 1; x = (x % m + m) % m;
while (n)
{ if (n & 1) res = (res * x) % m;
x = (x * x) % m; n >>= 1;
}
return res;
}
int dsu[500005], siz[5... | 12 | CPP |
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
def __init__(self, file):
self.newlines = 0
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buf... | 12 | PYTHON3 |
#include <bits/stdc++.h>
#define MOD 1000000007
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<ll> dlist;
typedef vector<dlist> matrix;
struct DS{
vector<bool> uni;
vector<int> p, c;
DS(int n): p(n, 0), c(n, 1), uni(n, false){
for(int i = 0; i < n; ++... | 12 | CPP |
#include <bits/stdc++.h>
#define LL long long
#define rep(i, s, t) for (register int i = (s), i##end = (t); i <= i##end; ++i)
#define dwn(i, s, t) for (register int i = (s), i##end = (t); i >= i##end; --i)
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getch... | 12 | CPP |
import sys
input = sys.stdin.buffer.readline
class UnionFind:
def __init__(self, n):
self.parent = [-1] * n
self.n = n
self.cnt = n
def root(self, x):
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(self.parent[x])
r... | 12 | PYTHON3 |
#include <stdio.h>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int p[500001];
int find(int a) {
if (p[a] != a) p[a] = find(p[a]);
return p[a];
}
bool dsu(int a, int b) {
a = find(a); b = find(b);
if (a == b) return 0;
p[b] = a;
return 1;
}
int main() {
int i, n, m;
long long T = 1;
vector<i... | 12 | CPP |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD=1e9+7;
int id[500005], sz[500005];
int find(int x){
while(x!=id[x]){
id[x]=id[id[x]];
x=id[x];
}
return x;
}
void unite(int i, int j){
int x=find(i), y=find(j);
if(sz[x]<sz[y]) swap(x, y);
sz[x]+=sz[y];
id[y]=x;
}
signed main(){
ios... | 12 | CPP |
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>
#define ... | 12 | CPP |
def findIndexGE(prefixSumsMax,startSum,query):
n=len(prefixSumsMax)
b=n
i=-1
while b>0:
while i+b<n and startSum+prefixSumsMax[i+b]<query:
i+=b
b//=2
i+=1
return i
def main():
t=int(input())
allans=[]
for _ in range(t):
n,m=readIntArr()
... | 13 | PYTHON3 |
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=... | 13 | CPP |
//int max = 2 147 483 647 (2^31-1)
//ll max = 9 223 372 036 854 775 807 (2^63-1)
#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
typedef v... | 13 | CPP |
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
pass
# region fastio
BUFSIZE = 8192
... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct tr { ll r, s; int i; };
bool g(tr &a, tr &b) {
if(a.r == b.r && a.s == b.s) return a.i < b.i;
else if(a.r == b.r) return a.s > b.s;
else return a.r < b.r;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(null... | 13 | CPP |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int t;
int n,m;
ll a[maxn];
ll res[maxn];
ll x[maxn];
int main()
{
cin >> t;
while(t--)
{
cin >> n >> m;
ll sum = 0;
ll ma = 0;
for(int i = 1;i <= n; ++i)
{
cin >> a[i];
sum += a[... | 13 | CPP |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(a,b) for(ll i=a;i<b;i++)
#define pii pair<ll,ll>
#define F first
#define S second
#define mp make_pair
#define pb push_back
ll t,n,m,x,y,bal,MX;
vector<ll>a,pre,mx;
ll tell(ll x){
ll st=1,en=n,md,ans=0;
while(st<=en){
md=(st+... | 13 | CPP |
#include<bits/stdc++.h>
using namespace std;
#define endl ("\n")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ll long long
#define llu long long unsigned
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inpotp freopen("input.txt", "r", stdin); ... | 13 | CPP |
from bisect import*
I=lambda:map(int,input().split())
for _ in range(*I(),):
n,m=I();p=[0];M=[0]
for v in I():p+=p[-1]+v,;M+=max(M[-1],p[-1]),
s=p[-1];a=[]
for x in map(int,input().split()):
r=0
if s>0:t=max((x-M[-1]+s-1)//s,0);r=t*n;x-=t*s
a+=[str(r+bisect_left(M,x)-1),'-1'][x>M[-1]],
print(*a) | 13 | PYTHON3 |
from collections import defaultdict
from bisect import bisect_right
import math
t=int(input())
for i in range(t):
n,u=map(int,input().split())
b=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=[]
s=sum(b)
pre=[0]
for j in range(n):
pre.append(pre[-1]+b[j])
... | 13 | PYTHON3 |
import sys
from bisect import bisect_left
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def solve():
n, m = map(int, input().split())
A = list(map(int, input().split()))
X = list(map(int, input().split()))
pref = []
ind = []
step = 0
for... | 13 | PYTHON3 |
t=int(input())
import math
import heapq
for _ in range(t):
n,m=map(int,input().split())
a=list(map(int,input().split()))
x=list(map(int,input().split()))
lis=[a[0]]
for i in range(1,n):
lis.append(lis[-1]+a[i])
one_round=lis[-1]
MAX=max(lis)
rests=[]
ans=[]
for q in x:
... | 13 | PYTHON3 |
import io
import os
from collections import Counter, defaultdict, deque
from bisect import bisect_left
def solve(N, M, A, X):
pref = [0]
for x in A:
pref.append(pref[-1] + x)
for i in range(1, N + 1):
pref[i] = max(pref[i], pref[i - 1])
pref.pop(0)
cycleLen = N
cycleSum = sum... | 13 | PYTHON3 |
import math
def answer(n,a,m):
s = 0
max_sum = a[0]
p_sums = [(a[0], 1)]
for i in range(n):
s+=a[i]
if s>max_sum:
max_sum = s
p_sums.append((s, i+1))
length = len(p_sums)
x = list(map(int, input().split()))
for i in range(m):
xi = x[i]
... | 13 | PYTHON3 |
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect... | 13 | PYTHON3 |
#include<stdio.h>
#define N 200007
#define ll long long
inline int read(){
int x=0,flag=1; char c=getchar();
while(c<'0'||c>'9'){if(c=='-') flag=0;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
return flag? x:-x;
}
int T,n,m,a[N],top,pos[N];
ll sta[N];
int main(){
T=read();
while(T--){
... | 13 | CPP |
// Author :: <Hitesh_Saini>
#include<bits/stdc++.h>
#define __speed() ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define dbg(x) cout << "(" << __LINE__ << ": "<< #x << " = " << x << ")\n"
#define Yes(x) print((x) ? "Yes" : "No")
#define tt int t; for (cin >> t; t--; )
#define f0(i, n) for (i = 0; i < (... | 13 | CPP |
from bisect import *
import math
for _ in range(int(input())):
n,m=map(int,input().split())
arr=list(map(int,input().split()))
xs=list(map(int,input().split()))
pre=[]
for i in range(n):
try:
pre.append((pre[-1][0]+arr[i],i))
except:
pre.append((arr[i],i))
... | 13 | PYTHON3 |
import math
from bisect import bisect_left, bisect_right
import sys
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
T = int(input())
for _ in range(T):
N, M = get_ints()
A = get_ints()
X = get_ints()
# Q = []
# for i in range(M):
# Q.append((X[i], i))
# Q.s... | 13 | PYTHON3 |
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include<bits/stdc++.h>
#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define FL cout.flush()... | 13 | CPP |
#include"bits/stdc++.h"
#define int long long
#define mod 1000000007
#define pf push_forward
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define f(i,in,n) for(i=in; i<n; ++i)
#define scant int t,t2055; cin>>t2055;for(t=1;t<=t2055;t++)
using namespace std;
int32_t main() {
ios_base::sync_... | 13 | CPP |
from math import ceil
for _ in range(int(input())):
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
mpfa = [0] * n
mpfi = 0
pf = mpfa[0] = a[0]
for i in range(1, n):
pf += a[i]
if pf > mpfa[i - 1]:
mpfi = i
mpfa[i] = p... | 13 | PYTHON3 |
from bisect import bisect_left
tc = int(input())
for _ in range(tc):
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
x = list(map(int, input().split()))
Val = sum(a)
process = []
ret = []
curr = 0
index = {}
for i in range(n):
curr += a[i]
... | 13 | PYTHON3 |
#include <bits/stdc++.h>
#define fu(i,a,b) for (long long i=a; i<=b; i++)
#define fd(i,a,b) for (long long i=a; i>=b; i--)
using namespace std;
typedef long long ll;
const ll N=2e5+10;
ll n,q,a[N],s[N],ma[N],query[N];
void Solve()
{
cin>>n>>q;
fu(i,1,n)
{
cin>>a[i];
}
fu(i,1,q)
{
... | 13 | CPP |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define lln long long int
#define ld long double
#define all(x) (x).begin(),(x).end()
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int MOD = 1e9 + 7;
int main(){
IOS;
int a1;
cin >> a1;
for(int TT=0;TT<a1;TT++){... | 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
int n, qq;
int ... | 13 | CPP |
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int get(vector<int> &a, int n, int k)
{
int low = 0, high = n - 1, ans = -1 ;
while (low <= high)
{
int mid = (low + high) / 2;
if (a[mid] >= k)
{
ans = mid + 1;
high = mid - 1;
}
... | 13 | CPP |
import sys
zz=1
sys.setrecursionlimit(10**5)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def fori(n):
return [fi() for i in range(n)]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def ii():
return input().rstrip()
def... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) "{" << (p).St << ", " << (p).Nd << "} "
#define list_format(i, n)... | 13 | CPP |
#include<bits/stdc++.h>
using namespace std;
template <class T> ostream &operator << (ostream &os, const vector<T> &p) { os << "["; for (auto&it : p) os << it << " "; return os << "]";}
template <class S, class T> ostream &operator << (ostream &os, const pair<S, T> &p) { return os << "(" << p.first << "," << p.second <... | 13 | CPP |
import os
import sys
from bisect import bisect_left
from collections import Counter
from io import BytesIO, IOBase
from math import ceil
def f(n):
return int(n)%3
def main():
from collections import Counter
for _ in range(int(input())):
n, m = map(int, input().split())
a = [int(X) for X ... | 13 | PYTHON3 |
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
#define ll long long
#define maxn 200005
ll t,n,m,a[maxn],k;
map<ll,ll> v;
ll bs(ll c){
ll l=0,r=k;
while(l<r){
ll m=(l+r)/2;
if(a[m]>=c) r=m;
else l=m+1;
}
if(r==k) return -1;
return v[a[l]];
}
int main(){
cin>>t;
... | 13 | CPP |
from bisect import bisect_left
import math
ii = lambda : int(input())
li = lambda:list(map(int,input().split()))
t = int(input())
for _ in range(t):
n,m = li(); a = li();xl = li()
mx = []; curSum = 0;mxind = [];res = []
for i in range(n):
curSum+=a[i]
if mx==[] or mx[-1]<curSum:
... | 13 | PYTHON3 |
import bisect
t = int(input())
for i in range(t):
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
x = list(map(int, input().split()))
pre = 0
max_e = -float('inf')
min_e = float('inf')
s = []
for j in range(n):
pre += a[j]
if pre > max_e:
... | 13 | PYTHON3 |
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007;
const int dx[] = { 0, 0, -1, 1, 1, -1, 1, ... | 13 | CPP |
#import sys
from bisect import bisect_left
#input = sys.stdin.readline
def solve():
n, m = map(int,input().split())
a = list(map(int,input().split()))
p = [0]*(n+1)
M = [0]*(n+1)
for i in range(n):
p[i+1] = p[i] + a[i]
M[i+1] = max(M[i], p[i+1])
s = p[-1]
ans = []
#print(p,M)
for x in map(int,input().spl... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc;cin>>tc;
while(tc--)
{
int n,m;cin>>n>>m;
vector<int> v(n);
for(int i=0;i<n;i++)cin>>v[i];
vector<long long> ps={v[0]}, ix={0};
long long sp=v[0];
for(int i=1;i<n;i++)
{
sp+=v[i];
if(sp>=ps.back()){ps.push... | 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi... | 13 | CPP |
from bisect import *
from random import *
from itertools import *
import sys
read = sys.stdin.readline
write = lambda x, end="\n": sys.stdout.write(x + end)
def naive(a, q, t, m):
if t <= 0 and m < q:
return -1
x = 0
for i in count():
x += a[i % len(a)]
if x >= q:
retur... | 13 | PYTHON3 |
#TESTING FAST IO AGAIN
import io,os,sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
in_length = int(input())
final_ouput = []
def find_minimum_stop(array, element, start, end):
mid = (start+end)//2
if start == end:
return 0
if element == array[mid]:
return mid
if element <= ... | 13 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200010];
ll x[200010];
ll sa[200010];
ll sama[200010];
int psama[200010];
inline ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
return f*x;
}
int main(){
... | 13 | CPP |
for k in range(int(input())):
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
x=list(map(int,input().split()))
b=0
c=0
d=0
e=[]
y=[]
n1=0
for i in range(n):
if d==0:
if a[i]>0:
b+=a[i]
e.append([b,i])
... | 13 | PYTHON3 |
from math import ceil
def find():
n, m = map(int, input().split())
a = list(map(int, input().split()))
x = list(map(int, input().split()))
sum_a = 0
pref = {}
pref_s = [0]
for j in range(n):
sum_a += a[j]
if sum_a not in pref:
pref[sum_a] = j
if a[j] > 0 ... | 13 | PYTHON3 |
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e6+5;
typedef long long ll;
long long n,m;
long long a[N],s[N],v[N],id[N];
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&n,&m);
for(int i=0;i<=n;i++)s[i]=v[i]=0;
ll tot=0;
for(int i=1;i<=n;i++){
scanf("%lld",&... | 13 | CPP |
/***************************/
/** Author : thantrongtri3 */
/***************************/
#include <bits/stdc++.h>
using namespace std;
namespace IO{
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = ""){
ios_base:... | 13 | CPP |
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wri... | 13 | PYTHON3 |
#include <iostream>
#include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define all(a) a.begin(), a.end()
#define forn(i, N) for (int i = 0; i < N; i++)
#define forab(i, a, b) for (int i = a; i < ... | 13 | CPP |
from collections import defaultdict,OrderedDict,Counter
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
# import numpy as np
from queue import Queue,PriorityQueue
from heapq import heapify,heappop,heappush
from statistics import median,mean
from math import gcd,sqrt,floor,factorial,ceil,log2,lo... | 13 | PYTHON3 |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)p... | 13 | CPP |
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector <ll> vec(n);
vector <pair<ll, int>> add;
ll sum1 = 0, sum2 = 0;
for (int i = 0; i < n; ++i) {
cin >> vec[i];
sum1 += vec[i];
if (su... | 13 | CPP |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
ll n,m,T,a[maxn],sum[maxn],maxx[maxn],ans[maxn];
int main(){
cin>>T;
while(T--){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i],sum[i]=sum[i-1]+a[i],maxx[i]=max(maxx[i-1],sum[i]);
for(int i=1;i<=m;i++){
ll x;cin>>x;
if(... | 13 | CPP |
import sys
input=sys.stdin.readline
from bisect import bisect_left
def getans(a,x,n,ma,s,ss,ssi):
p=ma
if s>0:
cnt=0
if x<=ma:
return ssi[bisect_left(ss,x)]
if x>ma:
cnt=(x-ma)//s
p+=cnt*s
while(1):
if x<=p:
return n*cnt... | 13 | PYTHON3 |
# from __future__ import print_function,division
# range = xrange
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10**9)
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10**9+7
def main():
for _ in range(int(input())):
n,m = [int(s) for s in input().split()]
... | 13 | PYTHON3 |
t = int(input())
for __ in range(t):
n, m = map(int, input().split(' '))
arr = [int(val) for val in input().split(' ')]
x = [int(val) for val in input().split(' ')]
stack = []
csum = 0
cmax = 0
for a in arr:
csum += a
cmax = max(cmax, csum)
stack.append(cmax)
re... | 13 | PYTHON3 |
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//read domain
typedef long long ll;
int dp[200001][2];
void build(int l, int r, vector<int> const &a, vector<int> &d, int curD = 0) {
if (r < l) {
return;
}
if (l == r) {
d[l] = curD;
return;
}
int m = l;
fo... | 13 | CPP |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Codeforces Round #702 (Div. 3)
Problem G. Old Floppy Drive
:author: Kitchen Tong
:mail: kctong529@gmail.com
Please feel free to contact me if you have any question
regarding the implementation below.
"""
__version__ = '3.2'
__date__ = '2021-03-14'
impor... | 13 | PYTHON3 |
from random import random, randint, randrange
from time import time
import random
import collections
import bisect
import os
import math
from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq ... | 13 | PYTHON3 |
from bisect import bisect_right
for _ in range(int(input())):
n, m = map(int,input().split())
arr = list(map(int,input().split()))
queries = list(map(int,input().split()))
cum = [0] * n
cum[0] = arr[0]
total = arr[0]
for i in range(1,n):
total += arr[i]
cum[i] = max(cum[i-1]... | 13 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int arr[200005];
ll nax,nim;
int n,m;
ll max(ll a,ll b){
return (a<b)?b:a;
}
ll min(ll a,ll b){
return (a<b)?a:b;
}
int main(){
int t;cin>>t;
while(t--){
cin>>n>>m;
ll nax=LONG_MIN;
ll s=0;
set<pair<l... | 13 | CPP |
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#pragma GCC optimize("O2", "O3", "fast")
#define _9trash no WA
#define ll long long
#define pb push... | 13 | CPP |
t = int(input())
xs = []
pref = []
n = 0
class SegmentTree:
def __init__(self, n):
self.t = [0 for _ in range(n * 4)]
def Build(self, v, tl, tr):
if tl + 1 == tr:
self.t[v] = pref[tl]
else:
tm = (tl + tr) >> 1
self.Build(v * 2 + 1, tl, tm)
self.Build(v * 2 + 2, tm, tr)
self.t[v] = max(self.t[... | 13 | PYTHON3 |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(X) (X).begin(),(X).end()
#define ln "\n"
#define out cout
#define NON_TOGLIERE ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define VI vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long... | 13 | CPP |
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef long long LL;
const int N = 200010;
int n, m;
LL a[N];
LL s[N];
struct Stack
{
LL s, id;
}stk[N];
int main()
{
int t;
cin >> t;
while (t -- )
{
... | 13 | CPP |
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint;
#include <bits/stdc++.h>
#define int long long
#define sint signed
#define endl "\n" // fflush(stdout);
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define VVVi vector<VVi>
#define Vm vector<mint>
#define ... | 13 | CPP |
import heapq
def solve(n, a, x):
delta = sum(a)
offset = [0] * len(x)
if delta > 0:
mx = None
s = 0
for i in range(n):
s += a[i]
if mx is None or mx < s:
mx = s
offset = [0] * len(x)
for i in range(len(x)):
laps = ... | 13 | PYTHON3 |
import math
import sys
import collections
import bisect
import heapq
testcases = int(sys.stdin.readline())
for _ in range(testcases):
arr = list(map(int,sys.stdin.readline().strip().split()))
n = arr[0]
m = arr[1]
ns = list(map(int,sys.stdin.readline().strip().split()))
ms = list(map(int,s... | 13 | PYTHON3 |
t = int(input())
for _ in range(t):
n, m = list(map(int ,input().split()))
a = list(map(int,input().split()))
xs = list(map(int,input().split()))
pref = [a[i] for i in range(n)]
pref_max = [a[i] for i in range(n)]
for i in range(1, n):
pref[i] += pref[i - 1]
pref_max[i] = max(pref[i], pref_max[i - 1])
dlt... | 13 | PYTHON3 |
from math import ceil
from bisect import bisect_left
def find():
n, m = map(int, input().split())
sum_a = 0
pref = {}
pref_s = [0]
ind = 0
for j in input().split():
sum_a += int(j)
if sum_a not in pref:
pref[sum_a] = ind
if sum_a > pref_s[-1]:
pre... | 13 | PYTHON3 |
//in dp prefix suffix sum helps..
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include <iterator>
#include <map>
#include<list>
#include <fstream>
#include<unordered_map>
#include<set>
#include<queue>
#define int long long
#define double ... | 13 | CPP |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Codeforces Round #702 (Div. 3)
Problem G. Old Floppy Drive
:author: Kitchen Tong
:mail: kctong529@gmail.com
Please feel free to contact me if you have any question
regarding the implementation below.
"""
__version__ = '3.0'
__date__ = '2021-03-14'
impor... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define t64 int64_t
#define rep(i,a,b) for(int i=a;i<b;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORe(i,a,b) for(int i=a;i<=b;i++)
#define FORr(i,a,b) for(int i=a;i>b;i--)
#define FORre(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#defi... | 13 | CPP |
#include <bits/stdc++.h>
#define w(x) int x; cin >> x; while(x--)
#define endl '\n'
#define mod 1000000007
#define ll long long
using namespace std;
ll pow(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
if(x == 0)
return 0;
while(y > 0) {
if(y & 1)
res = (res * x) % p;
... | 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL,LL> PLL;
const int INF = 0x3f3f3f3f, N = 2e5 + 10;
inline int lc(int u) {return u << 1;}
inline int rc(int u) {return u << 1 | 1;}
inline int lowbit(int x) {return x & (-x);}
LL a[N], s[N];
LL mm[N];
struct n... | 13 | CPP |
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <bits/stdc++.h>
using namespace std ;
const int inf = 1e9 ;
const int MAX = 2e5 + 10 ;
long long arr[MAX] ;
int val[MAX] , suff[MAX] ;
int n , q ;
vector<long long>v ;
long long sum = 0 ;
void compress()
{
for(int i = 1 ; i <= n... | 13 | CPP |
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(false);\
cin.tie(0);\
cout.tie(0)
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int t;
int n, m;
ll a[N], b[N];
ll c[N];
int main()
{
IO;
cin >> t;
while(t --)
{
cin >> n >> m;
for(int i = 1; i <= n; i... | 13 | CPP |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=3e5+10;
ll sum[maxn];
ll arr[maxn],xrr[maxn];
ll ans[maxn];
#define PII pair<ll,int>
int main()
{
int T;cin>>T;
while(T--)
{
int n,m;cin>>n>>m;
ll mx=-(1e12);
for(int i=1;i<=n;i++) cin>>arr[i];
... | 13 | CPP |
from __future__ import division, print_function
from itertools import permutations
import threading,bisect,math,heapq,sys
from collections import deque
# threading.stack_size(2**27)
# sys.setrecursionlimit(10**4)
from sys import stdin, stdout
i_m=9223372036854775807
def cin():
return map(int,sin().split())
def... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define N 200020
int a[N], x[N], y[N];
long long int s[N];
bool cmp(int i, int j) {
return s[i] < s[j];
}
int main() {
int tc;
scanf("%d", &tc);
for(int cc=0; cc<tc; cc++) {
int n, m;
scanf("%d %d", &n, &m);
for(int i=0; i<n; i... | 13 | CPP |
import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.... | 13 | PYTHON3 |
from math import log2
def found(a, value,m):
mid = len(a) // 2
low = 0
high = len(a) - 1
while low < high:
if value <= a[mid][0]:
high = mid
else:
low = mid + 1
mid = (low + high) // 2
if a[mid][0] >= value:
return m[mid]
else:
... | 13 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pii pair<int ,int>
#define PII pair<ll ,ll>
const int Max=1e9+100;
const ll MAX=1e18+500;
const ll sz=2e5+100;
map<ll,ll> mp;
int ma... | 13 | CPP |
from os import path
import sys,time
# mod = int(1e9 + 7)
# import re
from math import ceil, floor,gcd,log,log2 ,factorial,sqrt
from collections import defaultdict ,Counter , OrderedDict , deque
# from itertools import combinations
# from string import ascii_lowercase ,ascii_uppercase
# from bisect import *
from functoo... | 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////*****************//////////////////////////////////////
typedef long long ll;
ll z=1000000007;
ll fact[400005];
void buildfact()
{
fact[0]=1;
for(ll i=1;i<400005;i++)
{
fact[i]=(fact[i-1]*i)%z;
}
}
ll power(ll a,ll ... | 13 | CPP |
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in fil... | 13 | PYTHON3 |
#!/usr/bin/env python3
# set vim: fdm=marker sw=4 ts=4 et
import bisect
# {{{ IntervalTree
class IntervalTree:
@staticmethod
def get_depth(n):
depth = 0
i = 1
while i < n:
depth += 1
i <<= 1
return depth
def __init__(self, n):
self.n = n
... | 13 | PYTHON3 |
from bisect import bisect_left
import math
ii = lambda : int(input())
li = lambda:list(map(int,input().split()))
t = int(input())
for _ in range(t):
n,m = li()
a = li()
xl = li()
mx = []
curSum = 0
mxind = []
res = []
for i in range(n):
curSum+=a[i]
if mx==[] or mx[-1]<cu... | 13 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.