天天寄快递

 

思路:

  就是模拟,但有几个地方需要注意。

  1结果可能会很大,要开longlong。(这我注意到了)

  2要先把每个公司的得分加到K,(我就在 给每个数据的对应公司加分时出错了)

复制代码
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#define N 1000009
int n,m,s,k;
struct node{
    int e,t;
}q[N];
long long mark,tot,cnt,dt;
bool cmp( node  a,node b)
{
    if(a.e != b.e)    return a.e<b.e;
    else    return a.t > b.t;        
}
bool cmpp( node  a,node b)
{
    return a.t>b.t;        
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&s,&k);
    if(s<n)
    {
        cout<<-23333333;
        return 0;
    }
    
    for(int i=1,e,t;i<=m;i++)    
    {
        scanf("%d%d",&e,&t);
        if(t>=2)
            q[++cnt].e=e,q[cnt].t=t;
    }
    sort(q+1,q+1+cnt,cmp);
    for(int i=1;i<=n;i++)
    {
        while(q[dt].e<i)
            dt++;
        dt--;    //开始没加这一步,给公司加分时,弄错了
        tot=0;
        while(tot<k&&s>=1)        
            tot+=1LL*q[++dt].t-2,s--,q[dt].t=0;
        if(tot<k)
        {
            cout<<-23333333;
            return 0;
        }
        mark+=tot;
    }
    sort(q+1,q+cnt+1,cmpp);
    for(int i=1;i<=s;i++)
    if(q[i].t>=2)
    mark+=1LL*q[i].t-2;
    cout<<mark;
    return 0;
}
复制代码

小样例:

输入:

  

2 5 2 22
1 32
1 40
2 25
2 32
2 0

输出:

68

 

posted @   浪矢-CL  阅读(240)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示