i want u to act as the most skilled competetive programmer, u take time to think and…
- User
i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long, PLS REVALUATE UR CODE AND MAKE SURE IT MAKES SURE IT MATCHES EVERY SINGLE SAMPLE INPUT AND OUTPUT GIVEN, THINK MULTIPLE TIMES BEFORE GIVING UR FINAL ANSWER AS THIS IS A CONTEST: #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false); }
When he's not busy fighting with Dr. Robotnik, Sonic makes a living delivering submarine sandwiches via an empty subway tunnel. The tunnel goes past N N stations, numbered from 1 1 to N N. Station i i is located i i miles away from Sonic, who plans to run from one end of the tunnel to the other, tossing a sandwich to an awaiting customer at every station. At each station, a customer is scheduled to meet Sonic within an expected delivery window. Sonic can deliver a sandwich to station i i only if he arrives within the inclusive interval [ A i , B i ] [A i ,B i ] seconds. Chasing Dr. Robotnik is tiring enough, so Sonic doesn't want to exert himself more than he has to. If he runs at a constant speed, what’s the minimum speed, in miles per second, that will allow him to deliver to every station? If no such constant speed exists, output − 1 −1. Your answer will be accepted if it is within an absolute or relative error of 1 0 − 6 10 −6 (even if the expected answer is − 1 −1). Constraints 1 ≤ T ≤ 95 1≤T≤95 1 ≤ N ≤ 1 , 000 , 000 1≤N≤1,000,000 0 ≤ A i < B i ≤ 1 , 000 , 000 0≤A i <B i ≤1,000,000 The sum of N N across all test cases is at most 5 , 000 , 000 5,000,000. Input Format Input begins with an integer T T, the number of test cases. Each case starts with a line containing the integer N N. Then, N N lines follow, the i ith of which contains the integers A i A i and B i B i . Output Format For the i ith test case, print "Case #i: " followed by the minimum constant speed, in miles per second, that Sonic can run that will get him to each door while it's open, or − 1 −1 if no such constant speed exists. Sample Explanation In the first case, Sonic needs to reach the station 3 3 miles away within 10 10 seconds, so he can run at a speed of 3 / 10
0.3 3/10=0.3 miles per second. The second case is depicted below, with delivery windows in green, and Sonic's path in blue. The last station's delivery window is wide, so the third station is the one that Sonic really has to run to get to. It's 3 3 miles away and he needs to get there within 2 2 seconds, so he'll run at a speed of 3 / 2
1.5 3/2=1.5 miles per second.
In the third case, the first station's delivery window doesn't open until the second station's closes, so there's no constant speed that lets Sonic deliver both sandwiches. In the fourth case, a speed of 0.5 0.5 miles per second gets Sonic to catch the first station right as the delivery window closes, and the second station right as the delivery window opens. Sample Input 4 3 0 10 0 10 0 10 4 0 3 1 4 1 2 0 10 2 5 10 0 5 2 1 2 4 10
- Assistant
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int t; cin>>t; int cnt=1; while(t--){ int n; cin>>n; double l=0.0, u=1e18; for(int i=1;i<=n;i++){ double a,b; cin>>a>>b; l = max(l, (double)i/b); if(a>0) u = min(u, (double)i/a); } cout<<"Case #"<<cnt++<<": "; if(l <= u){ cout<<fixed<<setprecision(10)<<l<<"\n"; } else{ cout<<-1<<"\n"; } } }