이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
double a[N], b[N], suma[N], sumb[N], out;
int main() {
scanf(" %d", &n);
for (int i=1; i<=n; i++) scanf(" %lf %lf", &a[i], &b[i]);
sort(a+1, a+n+1, greater<double>()), sort(b+1, b+n+1, greater<double>());
for (int i=1; i<=n; i++) suma[i] = suma[i-1] + a[i], sumb[i] = sumb[i-1] + b[i];
// printf("suma : ");
// for (int i=0; i<=n; i++) printf("%lf ", suma[i]);
// printf("\nsumb : ");
// for (int i=0; i<=n; i++) printf("%lf ", sumb[i]);
// printf("\n");
for (int k=2; k<=2*n; k++) {
int l = max(1, k-n), r = min(n, k-1);
//printf("%d %d %d : ", k, l, r);
while (l < r) {
int mid = (l+r)/2;
if (suma[mid] < sumb[k-mid]) l = mid+1;
else r = mid;
}
//printf("%d %.4lf %.4lf ans %.4lf\n", l, suma[l-1], sumb[k-l], max(suma[l-1], sumb[k-l]) - k);
if (l == min(n, k-1) && suma[l] < sumb[k-l]) out = max(out, suma[l] - k);
else if (l == max(1, k-n) && suma[l] >= sumb[k-l]) out = max(out, sumb[k-l] - k);
else out = max(out, max(suma[l-1], sumb[k-l]) - k);
}
printf("%.4lf", out);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sure.cpp: In function 'int main()':
sure.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf(" %d", &n);
| ~~~~~^~~~~~~~~~~
sure.cpp:11:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | for (int i=1; i<=n; i++) scanf(" %lf %lf", &a[i], &b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |