SRM413 Div1Easy ArithmeticProgression

解法
誤差のない解法を目指す。

#define INF (1<<29)
#define EPS (1e-9)

class ArithmeticProgression {
public:
  double minCommonDifference(int a0, vector <int> seq) {
    if(seq.empty()) { return 0.; }
    for(int i=0; i<seq.size(); i++)
      seq[i] -= a0;
    double d_mn = 0., d_mx = INF;
    for(int i=0; i<seq.size(); i++) {
      d_mn = max(d_mn, seq[i] / (i+1.));
      d_mx = min(d_mx, (seq[i]+1) / (i+1.));
    }
    /*
    for(int i=0; i<(int)seq.size()-1; i++) {
      if(seq[i] != (int)(d_mn*(i+1))) return -1.;
    }
    cout << d_mn << " " << d_mx << endl;
    */
    return d_mn < d_mx ? d_mn : -1.;
  }
};