关于昨晚的Div3T3
  • 板块灌水区
  • 楼主Halberd_Cease天依天依天?
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/7/15 16:40
  • 上次更新2023/11/3 09:41:44
查看原帖
关于昨晚的Div3T3
441247
Halberd_Cease天依天依天?楼主2023/7/15 16:40

发在题目下有点丢脸,而且灌水区的人还要多一些

就是我看好像是在叉贪心的做法,正解是二分答案的 O(nlogn) 做法,于是我现在也不知道我赛时的贪心是否正确,个人感觉没问题,但是不知道属不属于他们说的乱搞做法,求证明或hack

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[500010],b[500010];
int now;
int ans;
signed main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
    for(int i=1;i<n;i++)
    {
        now=max(now,a[i]+b[i]+ans);
        if(now<a[i+1])
        {
            ans+=a[i+1]-now;
            now=a[i+1];
        }
    }
    cout<<ans;
}
2023/7/15 16:40
加载中...