Problem Link
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5;
void read(int s, int e, long arr[])
{
for(int i = s; i < e; i++)
{
cin >> arr[i];
}
}
int main()
{
int t, n, k, m;
long result;
long diff[N + 1], completed[N + 1], planned[N + 1], white[N + 1], black[N + 1], arr[2 * N + 1];
cin >> t;
while(t--)
{
cin >> n >> k >> m;
result = 0;
read(0, n, planned);
read(0, n, completed);
read(0, k, arr);
read(k, k + m, arr);
for(int i= 0; i < n; i++)
{
diff[i] = planned[i] - completed[i];
}
int index = k + m;
sort(diff, diff + n, greater<long>());
sort(arr, arr + index, greater<long>());
int i = 0;
int j = 0;
while(i < index && j < n)
{
if(arr[i] <= diff[j])
{
result += diff[j] - arr[i];
i++;
j++;
}
else
{
i++;
}
}
while(j < n)
{
result += diff[j++];
}
cout << result << endl;
}
}
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5;
void read(int s, int e, long arr[])
{
for(int i = s; i < e; i++)
{
cin >> arr[i];
}
}
int main()
{
int t, n, k, m;
long result;
long diff[N + 1], completed[N + 1], planned[N + 1], white[N + 1], black[N + 1], arr[2 * N + 1];
cin >> t;
while(t--)
{
cin >> n >> k >> m;
result = 0;
read(0, n, planned);
read(0, n, completed);
read(0, k, arr);
read(k, k + m, arr);
for(int i= 0; i < n; i++)
{
diff[i] = planned[i] - completed[i];
}
int index = k + m;
sort(diff, diff + n, greater<long>());
sort(arr, arr + index, greater<long>());
int i = 0;
int j = 0;
while(i < index && j < n)
{
if(arr[i] <= diff[j])
{
result += diff[j] - arr[i];
i++;
j++;
}
else
{
i++;
}
}
while(j < n)
{
result += diff[j++];
}
cout << result << endl;
}
}
Comments
Post a Comment