# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
987221 | Ghetto | Sails (IOI07_sails) | C++17 | 2 ms | 604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
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;
}
}
int 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';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |