Yogurt factory

一道简单的贪心模板题

http://poj.org/problem?id=2393

将每天的价格都放到最低就行了

核心思路:第i天最低的价格 = min(第i-1天最低的价格+s,第i天原本的价格)

有了思路,代码随便打

#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 10005
typedef long long ll;
ll c[maxn], y[maxn];
int main()
{
    ll cost = 0;
    ll n, s;
    cin >> n >> s;
    for (ll i = 0; i < n; ++i)
        cin >> c[i] >> y[i];
    for (ll i = 1; i < n;++i)
        c[i] = min(c[i], c[i - 1] + s);
    for (ll i = 0; i < n; ++i)
        cost += c[i] * y[i];
    cout << cost << endl;
    return 0;
}

 

全部评论

相关推荐

Rac000n:淘天-客户运营部-AI研发工程师,智能客服方向,暑期实习招聘,欢迎联系
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务