#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100100;
int n;
int A[MAX_N], B[MAX_N];
int main()
{
// Ulaz
cin>>n;
for(int i=0;i<n;i++)
{
cin>>A[i];
}
for(int i=0;i<n;i++)
{
cin>>B[i];
}
// Obrada
sort(A, A+n);
sort(B, B+n);
int rez = 0;
int profit = 0, loss = 0;
int sumA = 0, sumB = 0;
int a = n-1, b = n-1;
while(a != -1 and b != -1)
{
loss++;
if(sumA <= sumB)
{
if(a==-1) break;
sumA += A[a];
profit += A[a];
a--;
}
else
{
if(b==-1) break;
sumB += B[b];
profit += B[b];
b--;
}
if(profit - loss > rez)
{
rez = profit - loss;
}
}
// Izlaz
cout<<rez<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |