记录编号 |
452276 |
评测结果 |
AAAAAAAAAA |
题目名称 |
天天寄快递 |
最终得分 |
100 |
用户昵称 |
Youngsc |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.044 s |
提交时间 |
2017-09-19 10:19:59 |
内存使用 |
3.37 MiB |
显示代码纯文本
# include <algorithm>
# include <iostream>
# include <cstring>
# include <cstdio>
# include <queue>
# include <cmath>
# define R register
# define LL long long
using namespace std;
LL ans;
int n,m,s,k,d,t;
priority_queue <int> con[200010],q;
inline void in(R int &a){
R char c = getchar();R int x=0, f=1;
while(!isdigit(c)){if(c == '-') f=-1; c = getchar();}
while(isdigit(c)) x = (x<<1)+(x<<3)+c-'0', c = getchar();
a = x*f;
}
int main(){
freopen("expresss.in","r",stdin);
freopen("expresss.out","w",stdout);
in(n),in(m),in(s),in(k);
for(R int i=1; i<=m; ++i)
{
in(d),in(t);
con[d].push(t-2);
}
for(R int i=1; i<=n; ++i)
{
R int tot = 0;
while(s&&!con[i].empty()&&con[i].top()>0&&tot<k) tot += con[i].top(),con[i].pop(),s--;
if(tot < k) {printf("-23333333");return 0;}
ans += 1LL*tot;
}
// cout << ans << ' ';
if(!s) {printf("%lld",ans);return 0;}
for(R int i=1; i<=n; ++i)
while(!con[i].empty()&&con[i].top()>0){q.push(con[i].top()),con[i].pop();}
while(s&&q.top()>0) {ans+=1LL*q.top(),q.pop();s--;}
printf("%lld",ans);
return 0;
}