跳到正文

题解

题解 P1376 【机器工厂】

Jason224413约 1 分钟
原文
文章信息与版本

文章信息

发布
2016年9月21日
收录
2026年9月18日
更新
2026年11月14日
篇幅
约 1 分钟
获赞
74
题目
P1376

版本

  1. v1当前

很简单的一道题,时间O(n),空间O(1),注意ans用long long!否则会错。并且注意循环的其实值!!!

C++
#include<iostream>
using namespace std;
int main()
{
    int c,y;
    long long n,ans=0;
    int k,lastweek;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>c>>y;
        if(i==1) lastweek=c;
        else lastweek=min(lastweek+k,c);
        ans+=lastweek*y;
    }
    cout<<ans;
    //system("pause");
    return 0;
}
原文
存档评论40 条抓取于