codeforces_215D 贪心



只有全部赔钱和全部不赔钱两种情况, 而且每到一到一个地点的花费都是独立的, 所以可以对每一个地方的花费单独去贪心; 对两种的花费了来比较不容易出错;

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;

int main(){
    ll t, T, x, cost, n, m, ans;
    while(scanf("%lld%lld", &n, &m) == 2){
        ans = 0;
        for(int i=0;i<n;i++){
            scanf("%lld%lld%lld%lld", &t, &T, &x, &cost);
            if(t + m <= T) ans += cost;
            else{
                ll d = T -t, car;
                if(d <= 0){
                    ans += cost + x * m;
                    continue;
                }else{
                    car = (m % d == 0) ? m / d : (m / d) + 1;
                }
                ans += min(car * cost, cost + x * m);
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}