ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140789 | #704. 第K小的数 | Kogenta | 100 | 0ms | 1196kb | C++ | 825b | 2021-10-19 11:27:28 | 2021-10-19 11:27:29 |
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll l1,l2,r1,r2,k;
cin>>l1>>l2>>r1>>r2>>k;
if(l1>l2){
swap(l1,l2);
swap(r1,r2);
}
if(l1<=l2&&r1>=r2){
ll now=l2-l1,now2=r2-l2+1;
if(k<=now)cout<<l1+k-1<<endl;
else if(k<=now+now2*2){
k-=now;
if(k%2==0){
k/=2;
}
else k=k/2+1;
cout<<l2+k-1<<endl;
}
else{
k-=now+now2*2;
cout<<r2+k<<endl;
}
}
else if(r1>l2){
ll now=l2-l1,now2=r1-l2+1;
if(k<=now)cout<<l1+k-1<<endl;
else if(k<=now+now2*2){
k-=now;
if(k%2==0){
k/=2;
}
else k=k/2+1;
cout<<l2+k-1<<endl;
}
else{
k-=now+now2*2;
cout<<r1+k<<endl;
}
}
else{
if(k<r1-l1+1){
cout<<l1+k-1<<endl;
}
else{
k-=r1-l1+1;
cout<<l2+k-1<<endl;
}
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
8886 6221 78097 91055 74492
output:
44799
result:
ok single line: '44799'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
8485 4137 10391 92418 17568
output:
19797
result:
ok single line: '19797'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
8971 10295 71065 64956 44009
output:
31637
result:
ok single line: '31637'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
10684 8717 80822 67687 3240
output:
11320
result:
ok single line: '11320'
Test #5:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
3958 1898 85945 51639 18644
output:
12249
result:
ok single line: '12249'
Test #6:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
1793 1883 56708 52929 67645
output:
35660
result:
ok single line: '35660'
Test #7:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
9170 6442 44565277 52007711 60198538
output:
30107074
result:
ok single line: '30107074'
Test #8:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
6503 4398 42576185 41246506 39953330
output:
19982115
result:
ok single line: '19982115'
Test #9:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
8810 1858 83829062 7992207 44881061
output:
36899520
result:
ok single line: '36899520'
Test #10:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
2043 5959 76809751 61209845 80275334
output:
40141667
result:
ok single line: '40141667'
Test #11:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
3545 10083 89218900 13553199 23421584
output:
11717605
result:
ok single line: '11717605'
Test #12:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
9475 3919 29090865 62401189 66501333
output:
37423860
result:
ok single line: '37423860'
Test #13:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
10852 1890 62828646567693 870312128990889 105911095951062
output:
52955547981901
result:
ok single line: '52955547981901'
Test #14:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
2752 6137 841041922084030 428187075059640 226616769271876
output:
113308384640382
result:
ok single line: '113308384640382'
Test #15:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
5351 7789 956375681249281 133146269380995 871031626016150
output:
737885356648293
result:
ok single line: '737885356648293'
Test #16:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
1456 8032 419885911205932 252590350792861 422791002642414
output:
211395501325950
result:
ok single line: '211395501325950'
Test #17:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
4766 8958 955796731208347 306051927627717 1030986287617089
output:
724934360003094
result:
ok single line: '724934360003094'
Test #18:
score: 5
Accepted
time: 0ms
memory: 1192kb
input:
4675 8280 331918804272602 558377646810381 51805988620085
output:
25902994316519
result:
ok single line: '25902994316519'
Test #19:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
8246 2444 1000000000008245 1000000000002443 1589841792991229
output:
794920896500959
result:
ok single line: '794920896500959'
Test #20:
score: 5
Accepted
time: 0ms
memory: 1196kb
input:
7890 10350 1000000000007889 1000000000010349 787505365966203
output:
393752682992221
result:
ok single line: '393752682992221'