F - Fluctuation Limit

https://vjudge.net/contest/389195#problem/F

It is preferrable to read the pdf statment.

Cuber QQ has signed up for a gambling game, that challenges him to predict the stock price of Quber CC Limited, for the next following  nn days. He shall make his prediction by filling a table with nn intervals, the ii-th of which is the predicted interval [li,ri][li,ri] at the ii-th day. If all nn prices lie in the corresponding interval, Cuber QQ will win 1 million dollars. Otherwise, he will not earn a single penny.

As is well known, the stock price has a fluctuation limit. For simplicity, we assume the limit up and the limit down are both kk, which is an integer. That means, if the stock price at the ii-th day is xx, the price at the i+1i+1-th day is at most x+kx+k and at least xkx−k.

Cuber QQ wants to know whether it is possible to manipulate the stock price, without breaking the limitation above of course, so that he can have the 11 million dollars. Since his table has already been submitted, he cannot modify his predicted intervals any more. It has to be done secretly behind the scenes, and smartly cover it up so that no one will notice.

InputThe input starts with an integer TT (1T1051≤T≤105), denoting the number of test cases.

For each test case, the first line contains two space-separated integers nn and kk (2n1052≤n≤105, 0k1090≤k≤109), where nn is the number of days and kk is the fluctuation limit.

The ii-th line of the next nn lines contains two space-separated integers lili and riri (0liri1090≤li≤ri≤109), which is Cuber QQ's predicted interval in the ii-th day. A prediction is believed to be correct if the stock price ii-th day lies between lili and riri, inclusive.

It is guaranteed that the sum of all nn does not exceed 106106.
OutputFor each test case, first output a single line YES or NO, that states whether Cuber QQ will win the 1 million price.

If YES, in the next line, output a possible price series, a1,a2,,ana1,a2,…,an, where liairili≤ai≤ri (1in1≤i≤n) and |aiai+1|k|ai−ai+1|≤k (1in11≤i≤n−1). The integers should be separated with space.
Sample Input

2
3 1
1 6
2 5
3 6
2 3
1 5
10 50

Sample Output

YES
2 3 3
NO

Sponsor

 

题意:每次能在一个能够变换的区间变化,找区间

思路:

  正反两边扫描, 把左边的约束带到右边,反过来满足后面的方法决定前面的改变.

  同时满足正反两面变化的区间,最后剩下的为可行域(选最低的

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db;

const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7;

ll L[maxn] = {0};
ll R[maxn] = {0};
int main()
{
	ll l[maxn] = {0};
	ll r[maxn] = {0};
	ll n = 0 , k = 0;
	bool flag = 1;
	
    int T = 0;
    cin >> T;
    while(T--)
    {
        flag = 1;
        cin >> n >> k;
        for(int i = 0;i<n;i++)
        {
            cin >> L[i] >> R[i];
        }
        l[0] = L[0];
        r[0] = R[0];
        
        
        for(int i = 1;i<n;i++)
        {
            r[i] = min(R[i] , r[i-1] + k);
            l[i] = max(L[i] , l[i-1] - k);
            if(r[i] < l[i])
            {
            	flag = 0;
			}
        }
        for(int i = 1;i<n;i++)
        {
            r[n-1-i] = min(r[n-1-i] , r[n-i] + k);
            l[n-1-i] = max(l[n-1-i] , l[n-i] - k);
            if(r[i] < l[i])
			{
            	flag = 0;
			}
        }
        
        if(flag)
        {
            cout << "YES" <<endl;
            for(int i = 0;i<n;i++)
            {
          		cout << r[i];
            	if(i < n-1)
            	{
            		cout<<" ";
				}
			}
            cout <<endl;
        }
        else
        {
        	cout << "NO" <<endl;
		}
    }
    return 0;
}

/*
2
3 1
1 6
2 5
3 6
2 3
1 5
10 50
*/

  

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YukiRinLL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值