#JP9. NO.3 std

NO.3 std

T1

#include<bits/stdc++.h>
using namespace std;
long long n,m,top,btm;
int main()
{
	freopen("horse.in","r",stdin),freopen("horse.out","w",stdout);
	cin>>n>>m;
	vector<long long> a(n);
	for(auto &h:a) cin>>h;
	while(m--)
	{
		cin>>top,btm=0;
		for(auto &h:a)
		{
			if(h>=top)
			{
				h+=top-btm;
				break;
			}
			int dlt=max(0ll,h-btm);
			btm+=dlt;
			h+=dlt;
		}
	}
	for(auto h:a) cout<<h<<endl;
	return 0;
}

T2

#include<bits/stdc++.h>
int T;
std::string s;
int main()
{
    freopen("freetheend.in","r",stdin),freopen("freetheend.out","w",stdout);
	for(std::cin>>T;T--;puts(s.back()==48?"FD":"sst")) std::cin>>s;
	return (0^0);
}

T3

#include <bits/stdc++.h>
int n,a[400005],cnt,Min=2e9,ans;
std::string s;
int main()
{
	freopen("villager.in","r",stdin),freopen("villager.out","w",stdout);
	std::cin>>n>>s,s=s+'0';
	for(auto c:s) (c==49)&&++a[cnt] || a[cnt]&&cnt++;
	Min=std::min(Min,s[0]=='0'?(a[0]-1)/2:a[0]-1);
	Min=std::min(Min,s[n-1]=='0'?(a[cnt-1]-1)/2:a[cnt-1]-1);
	for(int i=1;i<cnt-1;i++) Min=std::min(Min,(a[i]-1)/2);
	for(int i=0;i<cnt;i++) ans+=std::ceil(a[i]*1.0/(Min*2+1));
	std::cout<<ans;
	return 0;
}

T4

#include<bits/stdc++.h>
#define N 200005
#define ll long long
using namespace std;
int n;
struct plan
{
	ll h,a,t;
}p[N];
bool check()
{
	for(int i=2;i<=n;i++)
		if(p[i].h>=p[i-1].h) return 0;
	return 1;
}
bool cmp(plan a,plan b)
{
	return a.t<b.t;
}
void work()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&p[i].h);
	for(int i=1;i<=n;i++) scanf("%lld",&p[i].a);
	for(int i=1;i<=n;i++) scanf("%lld",&p[i].t);
	sort(p+1,p+n+1,cmp);
	ll Max=0;
	for(int i=n;i>=2;i--)
	{
		if(p[i].h<p[i-1].h) continue;
		if(p[i].a>=p[i-1].a)
		{
			cout<<-1<<endl;
			return ;
		}
		Max=max(Max,(p[i].h-p[i-1].h)/(p[i-1].a-p[i].a)+1);
	}
	for(int i=1;i<=n;i++) p[i].h+=Max*p[i].a;
	if(check()) cout<<Max<<endl;
	else cout<<-1<<endl;
}
int main()
{
	freopen("bamboo.in","r",stdin),freopen("bamboo.out","w",stdout);
	int T;
	for(scanf("%d",&T);T--;work());
	return 0;
}