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;
}
目录
相关文章
|
8天前
|
C++
C/C++多重定义 Multi-defined解决方案
Error: L6200E: Symbol fTable multiply defined (by ../../build/system/StateMachine.LPC1768.o and ../../build/main.LPC1768.o).
|
7月前
|
XML 安全 数据安全/隐私保护
SAP Success Factor Single Sign On(单点集成) 的文档清单
SAP Success Factor Single Sign On(单点集成) 的文档清单
37 0
|
8月前
|
算法 程序员 Go
真实案例(万字长文):Bad Code vs Good Code in Golang
真实案例(万字长文):Bad Code vs Good Code in Golang
|
10月前
|
机器学习/深度学习
CF2A Winner(map+思维)
CF2A Winner(map+思维)
69 0
|
12月前
CF763A Timofey and a tree(思维)
CF763A Timofey and a tree(思维)
52 0
CF1341C. Nastya and Strange Generator(思维 模拟 构造)
CF1341C. Nastya and Strange Generator(思维 模拟 构造)
63 0
CF1567D. Expression Evaluation Error(思维 贪心)
CF1567D. Expression Evaluation Error(思维 贪心)
47 0
|
人工智能 BI
CF1398C. Good Subarrays(思维 前缀和)
CF1398C. Good Subarrays(思维 前缀和)
75 0
|
语音技术 网络架构 Windows
CF1560 E. Polycarp and String Transformation(思维 枚举)
CF1560 E. Polycarp and String Transformation(思维 枚举)
59 0
CF817C.Really Big Numbers(二分 思维)
CF817C.Really Big Numbers(二分 思维)
51 0