Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students
You are the gym teacher in the school.
There are nn students in the row. And there are two rivalling students among them. The first one is in position aa, the second in position bb. Positions are numbered from 11 to nn from left to right.
Since they are rivals, you want to maximize the distance between them. If students are in positions pp and ss respectively, then distance between them is |p−s||p−s|.
You can do the following operation at most xx times: choose two adjacent (neighbouring) students and swap them.
Calculate the maximum distance between two rivalling students after at most xx swaps.
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
The only line of each test case contains four integers nn, xx, aa and bb (2≤n≤1002≤n≤100, 0≤x≤1000≤x≤100, 1≤a,b≤n1≤a,b≤n, a≠ba≠b) — the number of students in the row, the number of swaps which you can do, and positions of first and second rivaling students respectively.
For each test case print one integer — the maximum distance between two rivaling students which you can obtain.
3
5 1 3 2
100 33 100 1
6 0 2 3
2
99
1
In the first test case you can swap students in positions 33 and 44. And then the distance between the rivals is equal to |4−2|=2|4−2|=2.
In the second test case you don't have to swap students.
In the third test case you can't swap students.
#include<bits/stdc++.h>
using namespace std ;
int n,x,a,b;
int main() {
int t;
cin>>t;
while(t--) {
cin>>n>>x>>a>>b;
if((abs(a-b)+x)>(n-)) cout<<n-<<endl;
else cout<<(abs(a-b)+x)<<endl;
}
return ;
}
Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students的更多相关文章
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题
A. Two Rival Students There are
- Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest
Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...
- Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)
题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...
- Educational Codeforces Round 76 (Rated for Div. 2)
传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...
- Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp
E. The Contest A team of three programmers is going to play a contest. The contest consists of
- Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 贪心
D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of
- Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题
C. Dominated Subarray Let's call an array
- Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题
B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...
- Educational Codeforces Round 76 (Rated for Div. 2) D题
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...
随机推荐
- 【vue 权威指南】 学习笔记 二
1.指令 1.1内部指令 基础指令:v-show , v-else , v-model , v-repeat , v-for , v-text , v-el , v-html , v-on , v-b ...
- usim卡介绍
- 数据预处理 | 使用 OneHotEncoder 及 get_dummuies 将分类型数据转变成哑变量矩阵
[分类数据的处理] 问题: 在数据建模过程中,很多算法或算法实现包无法直接处理非数值型的变量,如 KMeans 算法基于距离的相似度计算,而字符串则无法直接计算距离 如: 性别中的男和女 [0,1] ...
- Application Characteristics Of LED Keychain
LED keychains are essential camping and travel accessories. Very useful as a light source. There are ...
- window snmp
https://blog.csdn.net/weixin_30367543/article/details/99923014 https://jingyan.baidu.com/article/e3c ...
- python使用selenium驱动chromium防止浏览器自动升级失效!
python爬虫或者自动化项目中有时会用到selenium自动化测试框架,驱动chrom时由于谷歌浏览器自动升级,会造成驱动和浏览器版本不匹配问题,这时可以用到Chromium,这是谷歌推出用于开发目 ...
- STM 32 内部功能回顾
EXTI 外部中断 NVIC 嵌套的向量式中断控制器 AHB 是高级高性能内部总线,主要是用在CPU.DMA.DSP(数字信号处理) APB 是外围总线,I2C. 串口 APB 分为高速APB2( ...
- 题解【BZOJ4472】[JSOI2015]salesman
题面 树形\(\text{DP}\)与贪心的结合. 首先考虑树形\(\text{DP}\). 设\(dp_i\)表示从\(i\)出发,访问\(i\)的子树,并且最后回到\(i\)能获得的最大收益. 转 ...
- k线、指标绘制
我接触的绘制有两种:gdi+和qt绘图.可以灵活的绘制任何想要的东西. 先上效果图吧. 如下:基于gdi+的股指和股票的绘制.上面是沪深成分股实时生成的股票指数走势,下面是IF主力走势和开平仓位置. ...
- 关于spring boot集成MQTT
安装 说到mqtt,首先肯定要安装了,安装什么的地址:http://activemq.apache.org/ap...我本地是Windows的环境,所以装的是Windows版本,这里是第一个注意的地方 ...