Problem p02926 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 *      purpose :
 *      author  : kyomukyomupurin
 *      created :
 **/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec)                                                               \
  for (size_t _ = 0; _ < vec.size(); ++_) {                                    \
    std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';                 \
  }
// variadic template
template <typename T> inline void chmin(T &a, T b) {
  if (a > b)
    a = b;
  return;
}
template <typename T> inline void chmax(T &a, T b) {
  if (a < b)
    a = b;
  return;
}
// constant
const int INF = (1 << 30) - 1;       // 1.073741823e9
const int64 INF64 = (1LL << 62) - 1; // 4.611686018427387903e18
const int MOD = 1000000007;

const double pi = 3.141592653589793;
vector<double> x(101), y(101);
int n;

double naiseki(double x1, double y1, double x2, double y2) {
  return x1 * x2 + y1 * y2;
}

// 角度 theta の方向を最終的に向くとして計算
// theta は radian
double calc(const double &theta) {
  double res = 0.0;
  double dx = cos(theta), dy = sin(theta);
  for (int i = 0; i < n; ++i) {
    res += max(0.0, naiseki(dx, dy, x[i], y[i]));
  }
  return res;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  // auto start = chrono::system_clock::now();

  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int step = 25000000;

  double ans = 0.0;

  for (int i = 0; i < step; ++i) {
    double theta = 2.0 * pi * i / step;
    chmax(ans, calc(theta));
  }

  // auto end = chrono::system_clock::now();
  // auto dur = end - start;
  // auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  // cerr << msec << '\n';

  cout << setprecision(15) << ans << '\n';

  return 0;
}

Fixed submission:
/**
 *      purpose :
 *      author  : kyomukyomupurin
 *      created :
 **/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec)                                                               \
  for (size_t _ = 0; _ < vec.size(); ++_) {                                    \
    std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';                 \
  }
// variadic template
template <typename T> inline void chmin(T &a, T b) {
  if (a > b)
    a = b;
  return;
}
template <typename T> inline void chmax(T &a, T b) {
  if (a < b)
    a = b;
  return;
}
// constant
const int INF = (1 << 30) - 1;       // 1.073741823e9
const int64 INF64 = (1LL << 62) - 1; // 4.611686018427387903e18
const int MOD = 1000000007;

const double pi = 3.141592653589793;
vector<double> x(101), y(101);
int n;

double naiseki(double x1, double y1, double x2, double y2) {
  return x1 * x2 + y1 * y2;
}

// 角度 theta の方向を最終的に向くとして計算
// theta は radian
double calc(const double &theta) {
  double res = 0.0;
  double dx = cos(theta), dy = sin(theta);
  for (int i = 0; i < n; ++i) {
    res += max(0.0, naiseki(dx, dy, x[i], y[i]));
  }
  return res;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  // auto start = chrono::system_clock::now();

  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int step = 5000000;

  double ans = 0.0;

  for (int i = 0; i < step; ++i) {
    double theta = 2.0 * pi * i / step;
    chmax(ans, calc(theta));
  }

  // auto end = chrono::system_clock::now();
  // auto dur = end - start;
  // auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  // cerr << msec << '\n';

  cout << setprecision(15) << ans << '\n';

  return 0;
}