C. Min-Max Array Transformation Educational Codeforces Round 134 (Rated for Div. 2)

题意:给你一个a数组和一个d数组,这两个数组都是非递减的序列,让你通过构造b数组(数据保证一定能构成b数组),同时求出b数组的每个元素的最大的可能和最小的可能(数组的每个元素都单独分析)。

思路:

 对于元素最小的数组,只要看a数组中能不能小于当前的d数组的最小值,如果能就是这两个的差,不能就d数组的最小值往后挪。

对于元素最大的数组 ,最大能减的值初始化为j为n,从n到1逆向遍历,如果存在ai>di-1,那么ai-1的元素是不能和i之后的元素的组合的,因为如果组合了ai的元素就一定没有元素能够组合,就j=i-1就好了。

        // 10 20 30 36

        // 19 33 33 55

 比如是这种情况,首先b4=55-36 因为36>33,那么30只能访问到33这个下标(如果组合55的下标那么36就没有数可以组合)。

代码:

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N],ss[N],a[N],d[N];



int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		sc_int(n);
		for(int i =1;i<=n;i++)
		cin>>a[i];
		for(int i =1;i<=n;i++)
		cin>>d[i];		
		int i=1,j=n;
		for(int k =1;k<=n;k++)
		{
			while(a[k]>d[i])i++;
			s[k]=d[i]-a[k];
		}

		 i=1,j=n;
		//  cout<<i<<" "<<j<<endl;
		for(int k=n;k>=1;k--)
		{
			ss[k]=d[j]-a[k];
			if(a[k]>d[k-1])
			j=k-1;

		}
		for(int i =1;i<=n;i++)
		cout<<s[i]<<" ";
		cout<<endl;
		for(int i =1;i<=n;i++)
		cout<<ss[i]<<" ";
		cout<<endl;		
		// 10 20 30 36
		// 19 33 33 55
	}
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值