Problem p02926 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<pll> p(N);
  REP(i, N) { cin >> p[i].first >> p[i].second; }

  ll M = 10000000;
  double kaku = 2 * M_PI / M;
  double res = -1;
  REP(i, M) {
    double now = 0.01 + i * kaku;
    double x = sin(now);
    double y = cos(now);
    double x_tmp = 0, y_tmp = 0;
    // dump(now)
    // dump(x)
    // dump(y)
    REP(j, N) {
      if (p[j].first * x + p[j].second * y >= 0)
        x_tmp += p[j].first, y_tmp += p[j].second;
    }
    res = max(res, sqrt(x_tmp * x_tmp + y_tmp * y_tmp));
    // dump(res)
  }
  printf("%.10f\n", res);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<pll> p(N);
  REP(i, N) { cin >> p[i].first >> p[i].second; }

  ll M = 5000000;
  double kaku = 2 * M_PI / M;
  double res = -1;
  REP(i, M) {
    double now = 0.01 + i * kaku;
    double x = sin(now);
    double y = cos(now);
    double x_tmp = 0, y_tmp = 0;
    // dump(now)
    // dump(x)
    // dump(y)
    REP(j, N) {
      if (p[j].first * x + p[j].second * y >= 0)
        x_tmp += p[j].first, y_tmp += p[j].second;
    }
    res = max(res, sqrt(x_tmp * x_tmp + y_tmp * y_tmp));
    // dump(res)
  }
  printf("%.10f\n", res);
  return 0;
}