#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
typedef pair<ll,vector<int> >typ;
vector<int>tv[200010];
struct cmp
{
bool operator()(const typ&x,const typ&y)const
{
return x.fi>y.fi;
}
};
priority_queue<typ,vector<typ>,cmp>pq;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m,k;
cin>>n>>m>>k;
for(int i=0;i<n;i++)
{
int a,c;
cin>>a>>c;
tv[a-1].eb(c);
}
ll all=0;
for(int i=0;i<m;i++)
{
if(tv[i].empty())
{
for(int j=0;j<k;j++)
cout<<"-1\n";
cout.flush();
return 0;
}
sort(all(tv[i]));
all+=tv[i][0];
}
vector<int>zv(m,0);
pq.ep(all,zv);
int c=0;
while(!pq.empty()&&c<k)
{
ll cost=pq.top().fi;
vector<int>cur=pq.top().se;
pq.pop();
cout<<cost<<'\n';
c++;
for(int j=0;j<m;j++)
{
if(cur[j]+1<(int)tv[j].size())
{
cost-=tv[j][cur[j]];
cost+=tv[j][++cur[j]];
pq.ep(cost,cur);
cost-=tv[j][cur[j]];
cost+=tv[j][--cur[j]];
}
if(cur[j]!=0)
break;
}
}
for(int i=c;i<k;i++)
cout<<"-1\n";
cout.flush();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
617 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
616 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
617 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
5760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
617 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |