#include <iostream>
#include <queue>
#define FOR(i, s, t) for(i = s; i < t; i++)
using namespace std;
long long int freq[51], r[51], arr[51];
int main()
{
int t, p, l, i;
long int a, time, c;
cin >> t;
while(t--)
{
cin >> p >> l;
priority_queue<int, vector<int>, greater<int> >pq;
FOR(i, 0, 51)
{
freq[i] = 0;
r[i] = 0;
}
FOR(i, 0, l)
{
cin >> a;
freq[i] = 1;
arr[i] = r[i] = a;
pq.push(a);
}
time = 0;//start time
c = 0;
while(1)
{
time = pq.top();
pq.pop();
while(!pq.empty() && pq.top() == time)
pq.pop();
FOR(i, 0, l)
{
if(arr[i] == time)
{
c++;
freq[i]++;
arr[i] += r[i] * freq[i];
pq.push(arr[i]);
}
}
if(c >= p)
break;
}
cout << time << endl;
}
return 0;
}
#include <queue>
#define FOR(i, s, t) for(i = s; i < t; i++)
using namespace std;
long long int freq[51], r[51], arr[51];
int main()
{
int t, p, l, i;
long int a, time, c;
cin >> t;
while(t--)
{
cin >> p >> l;
priority_queue<int, vector<int>, greater<int> >pq;
FOR(i, 0, 51)
{
freq[i] = 0;
r[i] = 0;
}
FOR(i, 0, l)
{
cin >> a;
freq[i] = 1;
arr[i] = r[i] = a;
pq.push(a);
}
time = 0;//start time
c = 0;
while(1)
{
time = pq.top();
pq.pop();
while(!pq.empty() && pq.top() == time)
pq.pop();
FOR(i, 0, l)
{
if(arr[i] == time)
{
c++;
freq[i]++;
arr[i] += r[i] * freq[i];
pq.push(arr[i]);
}
}
if(c >= p)
break;
}
cout << time << endl;
}
return 0;
}
Comments
Post a Comment