이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
int n;
ld a[100009], b[100009];
int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
for(int i = 0; i < n; ++i){
scanf("%Lf", &a[i]);
scanf("%Lf", &b[i]);
}
sort(a, a+n, greater<ld>());
sort(b, b+n, greater<ld>());
ld ans = 0;
ld aProfit = 0;
int aIndex = 0;
ld bProfit = 0;
int bIndex = 0;
int spent = 0;
while(aIndex < n || bIndex < n){
spent += 1;
if(aIndex < n && (bIndex >= n || aProfit < bProfit)){
aProfit += a[aIndex++];
} else{
bProfit += b[bIndex++];
}
ans = max(ans, min(aProfit, bProfit)-spent);
}
printf("%.4lf", (double)ans);
}
컴파일 시 표준 에러 (stderr) 메시지
sure.cpp: In function 'int main()':
sure.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%Lf", &a[i]);
| ~~~~~^~~~~~~~~~~~~~
sure.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%Lf", &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... |