CF1445A Array Rearrangement 题解
Content
有 \(t\) 组询问,每组询问给定两个长度为 \(n\) 的数列 \(\{a_i\}_{i=1}^n,\{b_i\}_{i=1}^n\) 和一个整数 \(x\),求是否能够重新对两个数列进行排列,使得 \(\forall i\in[1,n],a_i+b_i\leqslant x\)。
数据范围:\(1\leqslant t\leqslant 100,1\leqslant n\leqslant 50,1\leqslant x\leqslant 1000,1\leqslant a_i\leqslant x,1\leqslant b_i\leqslant x,a_i\leqslant a_{i+1},b_i\leqslant b_{i+1}\)。
Solution
因为 \(a,b\) 两个数列都已经非降序排列,所以我们直接扫过去,看是否存在 \(i\in[1,n]\),使得 \(a_i+b_{n-i+1}>x\) 或者是否存在 \(i'\in[1,n]\),使得 \(a_{n-i'+1}+b_{i'}>x\)。如果上面的两个 \(i,i'\) 都存在,那么就无法满足题目的要求了,否则就可以。
Code
int t, n, x, a[100007], b[100007], a1[100007], b1[100007];
int main() {
//This program is written in Windows 10 by Eason_AC
getint(t);
while(t--) {
getint(n), getint(x);
_for(i, 1, n) getint(a[i]);
_for(i, 1, n) getint(b[i]);
int flag1 = 1, flag2 = 1;
_for(i, 1, n) if(a[i] + b[n - i + 1] > x) {flag1 = 0; break;}
_for(i, 1, n) if(a[n - i + 1] + b[i] > x) {flag2 = 0; break;}
if(flag1 || flag2) puts("Yes");
else puts("No");
}
return 0;
}
CF1445A Array Rearrangement 题解的更多相关文章
- Codeforces 1076G Array Game 题解
目录 题目大意 做法 代码 不想写昨天晚上cf的比赛题目所以来写题解摸摸鱼 题目大意 有一个在长度为\(k\)的正整数序列\(b\)上进行的游戏,一开始一个棋子放在位置\(1\),假如当前棋子的位置为 ...
- CF1095B Array Stabilization 题解
Content 有一个长度为 \(n\) 的数组 \(a_1,a_2,a_3,...,a_n\),现在需要从这些数中删除一个数,使得 \(\max\limits_{i=1}^na_i-\min\lim ...
- [Leetcode] Search in Rotated Sorted Array 系列
Search in Rotated Sorted Array 系列题解 题目来源: Search in Rotated Sorted Array Search in Rotated Sorted Ar ...
- LeetCode Can Place Flowers
原题链接在这里:https://leetcode.com/problems/can-place-flowers/description/ 题目: Suppose you have a long flo ...
- Codefoeces 734F. Anton and School 数学
Codefoeces 734F 题目大意: 给定两个正整数序列\(b,c\)构造一个正整数序列\(a\)使其满足 \[ \left\{ \begin{array}{} b_i=(a_i\text{ a ...
- 算法与数据结构基础 - 双指针(Two Pointers)
双指针基础 双指针(Two Pointers)是面对数组.链表结构的一种处理技巧.这里“指针”是泛指,不但包括通常意义上的指针,还包括索引.迭代器等可用于遍历的游标. 同方向指针 设定两个指针.从头往 ...
- 【题解】【数组】【查找】【Leetcode】Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- 【LeetCode题解】数组Array
1. 数组 直观地看,数组(Array)为一个二元组<index, value>的集合--对于每一个index,都有一个value与之对应.C语言中,以"连续的存储单元" ...
- LeetCode题解33.Search in Rotated Sorted Array
33. Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some piv ...
随机推荐
- python3使用concurrent执行多进程任务
技术背景 随着计算机技术的发展,诸如GPU和超算平台等越来越发达,这些技术的本质其实并没有带来算法上的革新,之所以能够提升计算的速度和规模,很大程度上是因为分布式和并行计算的优势.这里我们介绍一个简单 ...
- 9 Days 停课修炼题解集
xj4604 排序 \(n,k <= 1e5\). 先考虑二分出这个值,check 有多少段的平均值小于这个 mid,这个在之前的复活赛中是原题 T4,数形结合,$ \text{Average} ...
- Python使用print打印时,展示内容不换行
原理 Python的print()函数中参数end='' 默认为\n,所以会自动换行; 默认的print()函数: print(end='\n') 方案 Python 2: 在print语句的末尾加上 ...
- Xshell初步设置
目录 双击复制,右击粘贴 双击复制全路径 复制窗口:双击窗口 编码:设置utf-8 外观设置: 窗口化文件传输 vim中使用鼠标点击移动 隐藏/出现菜单栏 ctrl+鼠标控制字体大小 alt+O 弹出 ...
- 巩固java第六天
巩固内容: HTML 空元素 没有内容的 HTML 元素被称为空元素.空元素是在开始标签中关闭的. <br> 就是没有关闭标签的空元素(<br> 标签定义换行). 在 XHTM ...
- 学习java 7.2
学习内容:案例一:斐波那契数列从1开始作为第一个数,求第20个数 public class Test { public static void main(String[ ] args){ int[ ] ...
- nit是虱子的卵
如题.[牛津] (egg of a) louse or other parasitic insect 虱或其他寄生虫(的卵). 忘了在那个帖子里说nit: 虱子了. 为了凑字数,迄今为止六级/考研单词 ...
- acknowledge
accord+knowledge. accord好几个意思,knowledge不遑多让,We gotta acknowledge the word acknowledge has many meani ...
- day04 查找关键字
day04 查找关键字 昨日内容回顾 基本数据类型之日期相关类型 date :年月日 time :时分秒 datetime:年月日时分秒 year :年 基本数据类型之枚举与集合类型 # 枚举 多选一 ...
- 循环队列/顺序队列(C++)
队列(queue)是一种限定存取位置的线性变.他允许在表的一端插入,在另一端删除.这个和计算机调度策略中的先来先服务FCFS(First Come/First Served)是一样的.队列中可以插入的 ...