Today I installed Sublime Text 3 and compiled a C++ file. After compiling, I got an error that said: "Bad file descriptor." I read posts with similar errors, but I can't seem to find a solution.
Here's my code:
#include <bits/stdc++.h>
using namespace std;
#define SYNC ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define alln(x, n) (x) + 1, (x) + 1 + (n)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define times_used \
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" \
<< "\n"
#define task " "
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
const int N = 5005;
ll a[N], n, res = 0;
int main() {
SYNC;
#ifndef ONLINE_JUDGE
freopen("/home/steven/temp/input.txt", "r", stdin);
freopen("/home/steven/temp/error.txt", "w", stderr);
freopen("/home/steven/temp/output.txt", "w", stdout);
#endif
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n - 2; i++) {
int k = i + 2;
for (int j = i + 1; j <= n - 1; j++) {
while (a[k] < a[i] + a[j] && k <= n)
k++;
res += k - (j + 1);
}
}
cout << res;
return 0;
}