费用报销(蓝桥2022国赛)(spfa)

费用报销 - 蓝桥云课 (lanqiao.cn)

输入

4 16 3
1 1 1
1 3 2
1 4 4
1 6 8

输出

10
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b;i ++ )
#define fd(i,a,b) for(int i=a;i>=b;i -- )
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

typedef long long LL;
typedef vector<vector<LL>> VVL;

typedef pair<int,int> PII;

const int N = 1e5+ 10,M = N *4,INF = 0x3f3f3f3f ;


int n,m,k;


int day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int s[13];
PII q[N];
int h[N],e[M],w[M],idx,ne[M],d[N];
bool st[N];

void add(int a,int b,int c)
{
    e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}

int spfa(int now)
{
    ms(d,-0x3f);
    ms(st,0);
    d[now] =0;
    priority_queue<PII> q;
    q.push({0,now});
    
    while(q.size())
    {
        auto t = q.top();q.pop();
        st[t.y]=0;
        
        for(int i=h[t.y];~i;i=ne[i])
        {
            int j = e[i];
            if(d[j] < d[t.y] + w[i])
            {
                d[j] = d[t.y] + w[i];
                if(!st[j])
                {
                    st[j] = 1; 
                q.push({d[j],j});
                }
            }
        }
    }
    
    int ans =0 ;
    
    fu(i,0,n-1)ans =max(ans,d[i]);
    
    return ans;
}



inline void solve()
{
//    cin >> n>> m>> k;
    scanf("%d%d%d",&n,&m,&k);
    fu(i,1,12) s[i] = s[i-1] + day[i];
    
    fu(i,0,n-1)
    {
        int a,b,c;
//        cin >> a>>b >> c;
        scanf("%d%d%d",&a,&b,&c);
        int d=s[a-1] + b;
        q[i] = {d,c};
    }
    sort(q,q+n);
    ms(h,-1);
    fu(i,0,n-1)
    fu(j,i+1,n-1)
    {
        if(q[j].x- q[i].x>= k)
        add(i,j,min(q[j].y,m));    
    }    
    
    int res =0;
    fu(i,0,n-1)
    res = max(res,q[i].y + spfa(i));
    
    cout << res <<endl;
            
}

signed main()
{
//  freopen("1.txt","w",stdout);
//     ios

    int t=1;
//    cin>>t;
    int now = 1;
    while(t -- )
    {
//      cout<<"Case "; 
//      cout<<"Scenario #"; 
//      cout<< now ++ <<": ";
//      cout<< now ++ <<": \n";
        solve();
    }


    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值