-
Notifications
You must be signed in to change notification settings - Fork 52
/
1257 A.Two Rival Students.cpp
113 lines (75 loc) · 1.13 KB
/
1257 A.Two Rival Students.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
problem name:1257 A.Two Rival Students
problem link:https://codeforces.com/contest/1257/problem/A;
status:accepted;
author:mohand sakr;
*/
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n,x,a,b;
cin>>n>>x>>a>>b;
int curdist=abs(a-b);
vector<int> vect;
vect.push_back(curdist);
if(x){
if(a<=b){
if(a>1){
int newa=a;
int newb=b;
if((x>a-1)){
newa=newa-1;
x-=newa;
newa=1;
newb=(newb+x<=n)?newb+x:n;
}
else {
newa=a-x;
}
vect.push_back(abs(newa-newb));
}
else {
int newa=a;
int newb=(x+b<=n)?x+b:n;
vect.push_back(abs(newa-newb));
}
}
else {
if(b>1){
int newa=a;
int newb=b;
if((x>b-1)){
newb=newb-1;
x-=newb;
newb=1;
newa=(newa+x<=n)?newa+x:n;
}
else {
newb=b-x;
}
vect.push_back(abs(newa-newb));
}
else {
int newb=b;
int newa=a;
if((x+a)<n){
newa=x+a;
}
else{
newa=n;
}
vect.push_back(abs(newb-newa));
}
}
}
int len=vect.size();
sort(vect.begin(),vect.end());
cout<<vect[len-1]<<endl;
}
return 0;
}