社区讨论
9分求调
P1868饥饿的奶牛参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mj8eonsw
- 此快照首次捕获于
- 2025/12/16 17:54 3 个月前
- 此快照最后确认于
- 2025/12/19 18:55 3 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
struct grass{
int h,t,l;
}a[150000];
bool cmp(grass q,grass w){
return q.t < w.t;
}
int main(){
int n;
int gress=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].h>>a[i].t;
a[i].l = a[i].t - a[i].h + 1;
}
sort(a,a+n,cmp);
int last_t = -1;
for(int i=0;i<n;i++){
if(a[i].h > last_t){
gress += a[i].l;
last_t = a[i].t;
}
}
cout<<gress;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...