AC in C++14 but WA on C++17(64)

Revision en1, by arnav2004, 2021-05-29 13:39:24

I was solving this bugabooLink to the bugaboo.

Here's my code:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const ll INF = 1e18;
const int MOD = 1e9+7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int a,b,c;
		cin>>a>>b>>c;
		if(c==a){
			cout<<1<<"\n";
			continue;
		}
		if(c <= (a+b) / 2){
			cout<<2<<"\n";
			continue;
		}
		ll start = 1;
		ll high = (1LL<<40);
		ll mini = 0;
		double te = 0;
		while(start<=high){
			ll mid = (start+high)/2;
			ll sum = (1LL * mid * a) + (1LL*(mid-1)*b);
			double avg = (0.0000+sum) / (0.0000+mid+mid-1);
			if(avg>=c){
				mini = mid;
				start = mid+1;
			}
			else
				high = mid-1;
		}
		te = (a+b)/2;
		ll ans = 2;
		for(ll mid = mini;mid<=mini+100;mid++){
			ll sum = (1LL * mid * a) + (1LL*(mid-1)*b);
			double avg = (0.0000+sum) / (0.0000+mid+mid-1);
			if(abs(avg-c)<abs(te-c)){
				te = avg;
				ans = mid+mid-1;
			}
		}
		cout<<ans<<"\n";
	}
}

This code got AC in C++14 and WA in C++17(64). Is it this happening maybe because of some precision errors or is there any other reason?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English arnav2004 2021-05-29 13:39:24 1303 Initial revision (published)