CF761D Dasha and Very Difficult Problem(构造 思维)

简介: CF761D Dasha and Very Difficult Problem(构造 思维)

linkkk

题意:


现有a[i],b[i]两个数组(l<=a[i]<=b[i]<=r),我们定义p,c两个数组,其中c[i]=b[i]-a[i],p数组是c数组的相对大小,现给你a和p数组,把任意满足的一组b数组求出来.如果没有满足的,则输出‘-1’(没有引号)

思路:

先按照p从小到大排序,然后贪心的去构造,尽可能的让b i小,并且还要满足l < = b i < = r

代码:

// Problem: D. Dasha and Very Difficult Problem
// Contest: Codeforces - Codeforces Round #394 (Div. 2)
// URL: https://codeforces.com/problemset/problem/761/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100;
int n,l,r,ans[maxn],id[maxn];
struct node{
  int a,p;
}a[maxn];
bool cmp(node a,node b){
  return a.p<b.p;
}
int main(){
  cin>>n>>l>>r;
  for(int i=1;i<=n;i++) cin>>a[i].a;
  for(int i=1;i<=n;i++) cin>>a[i].p,id[a[i].p]=i;
  sort(a+1,a+1+n,cmp);
  ans[id[a[1].p]]=l;
  int las=l-a[1].a+1;
  for(int i=2;i<=n;i++){
    ans[id[a[i].p]]=max(l,las+a[i].a);
    if(ans[id[a[i].p]]>r){
      puts("-1");return 0;
    }
    las=max(las,ans[id[a[i].p]]-a[i].a)+1;
  }
  for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
  return 0;
}
目录
相关文章
|
11天前
|
数据可视化
R语言马尔可夫链(MARKOV CHAIN, MC)模拟赌徒破产模型GAMBLER’S RUIN PROBLEM可视化
R语言马尔可夫链(MARKOV CHAIN, MC)模拟赌徒破产模型GAMBLER’S RUIN PROBLEM可视化
16 0
|
3月前
|
C++
C/C++多重定义 Multi-defined解决方案
Error: L6200E: Symbol fTable multiply defined (by ../../build/system/StateMachine.LPC1768.o and ../../build/main.LPC1768.o).
|
12月前
CF763A Timofey and a tree(思维)
CF763A Timofey and a tree(思维)
47 0
CF1341C. Nastya and Strange Generator(思维 模拟 构造)
CF1341C. Nastya and Strange Generator(思维 模拟 构造)
61 0
CF1567D. Expression Evaluation Error(思维 贪心)
CF1567D. Expression Evaluation Error(思维 贪心)
46 0
|
人工智能 BI
CF1398C. Good Subarrays(思维 前缀和)
CF1398C. Good Subarrays(思维 前缀和)
74 0
|
语音技术 网络架构 Windows
CF1560 E. Polycarp and String Transformation(思维 枚举)
CF1560 E. Polycarp and String Transformation(思维 枚举)
57 0
CF817C.Really Big Numbers(二分 思维)
CF817C.Really Big Numbers(二分 思维)
50 0
|
机器学习/深度学习 算法 定位技术
[2019 EC Final] Flow | 贪心 + 思维
这m条边的容量都是≥ 0 的,在某一条便的容量> 0 的时候,可以进行若干次操作(也可以为0,即不进行操作):{ 选择一条容量大于0的边,将他的容量-1,然后选择一条其他的边,让这条边的容量+1 } 问在图中的最大流尽可能大的情况下,最少的操作步数是多少?
118 0
[North Central NA Contest 2018] Rational Ratio | 规律 细节模拟
Description Every (positive) rational number can be expressed as a ratio of two (positive) integers. However, in decimal form, rational numbers often have an infifinitely repeating pattern, e.g., 1/7 = 0.142857142857142857…
93 0
[North Central NA Contest 2018] Rational Ratio | 规律 细节模拟