Thứ Hai, 18 tháng 4, 2022

DBELL C++


#include <bits/stdc++.h>
using namespace std;
int f[300]={0,1,1,2,2,1,2,2,3,3,1,2,2,3,3,1,2,2,3,3};
int a[1000];
int w,n,minx=1e6,s=0;
void tao()
{
	for(int i=20;i<=100;i++)
	{
		f[i] = i/20 + f[i%20];
	}
}
void nhap()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	cin>>w;
}
void giai()
{
	if(s<=w && f[w-s]<minx) minx =f[w-s];
	for(int i=1;i<=n;i++)
	{
		s -= a[n+1-i];
		if(s<=w && f[w-s]+i<minx)
		{
			minx = f[w-s]+i;
		}
	}
	cout<<minx;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	freopen("dbell.inp","r",stdin);
	freopen("dbell.out","w",stdout);
	nhap();
	tao();
	giai();
}


Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.