2020牛客多校第八场 K Kabaleo Lite

题目链接

Tired of boring WFH (work from home), Apollo decided to open a fast
food restaurant, called Kabaleo Lite. The restaurant serves n kinds of
food, numbered from 1 to n. The profit for the i-th kind of food is
ai . Profit may be negative because it uses expensive ingredients. On
the first day, Apollo prepared bi dishes of the i-th kind of food.
The peculiarity of Apollo’s restaurant is the procedure of ordering
food. For each visitor Apollo himself chooses a set of dishes that
this visitor will receive. When doing so, Apollo is guided by the
following rules: every visitor should receive at least one dish. each
visitor should receive continuous kinds of food started from the first
food. And the visitor will receive exactly 1 dish for each kind of
food. For example, a visitor may receive 1 dish of the 1st kind of
food, 1 dish of the 2nd kind of food, 1 dish of the 3rd kind of food.
What’s the maximum number of visitors Apollo can feed? And he wants to
know the maximum possible profits he can earn to have the maximum of
visitors.

The first line of the input gives the number of test case,T
(101≤T≤10). test cases follow.Each test case begins with a line
containing one integers n ( 10^51≤n≤10 5 ), representing the number of
different kinds of food. The second line contains n space-separated
numbers ai(10≤ai≤10 9 ), where ai denotes the profit of one dish of
the i-th kind. The third line contains n space-separated numbers bi
where bi denotes the number of the i-th kind of dishes.

ac代码如下:

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)	
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
const ll mod = 1e9 + 7;
template <typename _Tp> inline void read(_Tp&x);
inline void print(__int128 x);
template <typename _Tp> inline void read(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-')flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}
inline void print(__int128 x) {
	if(x<0) {x=-x;putchar('-');}
	if(x>9) print(x/10);
	putchar(x%10+'0');
}
ll dp[maxn]  ;
ll n ;
struct node{
	int a,b,aa ,ans;
}x[maxn]; 
ll cnt ;
void solve()
{
	scanf("%lld",&n) ;
	for (int i = 1; i <= n; i++) 
	{
        cin >> x[i].a;
        x[i].aa = x[i - 1].aa + x[i].a;
    }
    cin >> x[1].b;
    for (ll i = 2; i <= n; i++) 
	{
        cin >> x[i].b;
        if (x[i].b > x[i - 1].b)
        	x[i].b = x[i - 1].b;
    }
	ll cus = x[1].b ;
	__int128 ans = x[1].aa * x[1].b  ;
	for(ll i = 2 ;i <= n ; i++)
	{
		ll c = x[i-1].aa ;
		if(x[i].aa >= x[i-1].aa )
			ans += x[i].a * x[i].b ;
		else
		{
			ll flag = 0 ;
			while(x[i].aa < c && i <= n)
			{
				if(i == n)
					flag = 1 ;
				i++ ;
			}
			if(flag == 0)
				ans += ((x[i].aa - c) * x[i].b) ; 
		}
	}
	printf("Case #%lld: %lld ",cnt,cus) ;
	print(ans) ;
	printf("\n") ;
}
int main()
{
	cnt = 0 ;
	T{
		cnt++ ;
		solve() ; 
	}
	return 0; 
} 

猜你喜欢

转载自blog.csdn.net/zcmuhc/article/details/107771739
今日推荐