# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
987224 |
2024-05-22T11:07:25 Z |
Ghetto |
Sails (IOI07_sails) |
C++17 |
|
48 ms |
3012 KB |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define int lint
const int MAX_H = 1e5 + 5;
const lint INF = 3e18;
int n;
vector<int> hs;
lint s;
int w[MAX_H];
void precomp() {
for (int h = 1; h <= 1e5; h++) {
int i = lower_bound(hs.begin(), hs.end(), h) - hs.begin();
w[h] = n - i;
}
}
signed main() {
// freopen("sails.in", "r", stdin), freopen("sails.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
int h; cin >> h;
hs.push_back(h);
lint new_s; cin >> new_s;
s += new_s;
}
sort(hs.begin(), hs.end());
precomp();
auto consec_sum = [] (lint x) { return x * (x + 1) / 2; };
lint ans = INF, sum = 0;
for (int h = 1e5; h >= 1; h--) {
if (s <= h * (lint) w[h]) {
lint new_ans = sum + h * consec_sum(s / h - 1) + (s / h) * (s % h);
ans = min(ans, new_ans);
}
s -= w[h], sum += consec_sum(w[h] - 1);
if (s < 0) break;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1112 KB |
Output is correct |
2 |
Correct |
3 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
2256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
2756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
2964 KB |
Output is correct |
2 |
Correct |
33 ms |
2504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
3012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |