Problem Link
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define sf(i) scanf("%d",&i)
#define pf(i) printf("%d ", i)
using namespace std;
const int N = 10000;
int main()
{
int t, n, k1, k2, k3;
int arr[N + 1];
int sum[2015];
int index;
long s, val;
sf(t);
while(t--)
{
sf(n), sf(k1), sf(k2), sf(k3);
priority_queue<long, vector<long>, greater<long>> pq;
index = 0;
s = 0;
for(int i = 0; i < n; i++)
{
sf(arr[i]);
}
for(int i = 1; i < n; i++)
{
arr[i] += arr[i - 1];
}
for(int i = 0; i < n; i++)
{
for(int j = i; j < n; j++)
{
if(i == 0)
{
val = arr[j];
}
else
{
val = arr[j] - arr[i - 1];
}
if(index < k3)
{
pq.push(val);
index++;
}
else
{
long minVal = pq.top();
if(val > minVal)
{
pq.pop();
pq.push(val);
index++;
}
}
}
}
int k = k3 - 1;
while(!pq.empty())
{
sum[k--] = pq.top();
pq.pop();
}
printf("%d %d %d\n",sum[k1 - 1],sum[k2 - 1],sum[k3 - 1]);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define sf(i) scanf("%d",&i)
#define pf(i) printf("%d ", i)
using namespace std;
const int N = 10000;
int main()
{
int t, n, k1, k2, k3;
int arr[N + 1];
int sum[2015];
int index;
long s, val;
sf(t);
while(t--)
{
sf(n), sf(k1), sf(k2), sf(k3);
priority_queue<long, vector<long>, greater<long>> pq;
index = 0;
s = 0;
for(int i = 0; i < n; i++)
{
sf(arr[i]);
}
for(int i = 1; i < n; i++)
{
arr[i] += arr[i - 1];
}
for(int i = 0; i < n; i++)
{
for(int j = i; j < n; j++)
{
if(i == 0)
{
val = arr[j];
}
else
{
val = arr[j] - arr[i - 1];
}
if(index < k3)
{
pq.push(val);
index++;
}
else
{
long minVal = pq.top();
if(val > minVal)
{
pq.pop();
pq.push(val);
index++;
}
}
}
}
int k = k3 - 1;
while(!pq.empty())
{
sum[k--] = pq.top();
pq.pop();
}
printf("%d %d %d\n",sum[k1 - 1],sum[k2 - 1],sum[k3 - 1]);
}
return 0;
}
Comments
Post a Comment