外国人很良心的啊,这题比NOIP那题还简单……

不用管他最后的位置,因为移动的次数肯定是恒定的,所以维护在每一个柱子的位置能飞到的范围,递推下去即可。

#include<bits/stdc++.h>
using namespace std;
int n,x,y,ans,pos;
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
int main(){
    n=read();int ttt=read();
    for(int i=1;i<=n;i++){
        int d=read(),l=read(),r=read();
        pos+=d-x;y-=d-x;x=d;
        if(y<=l){int t=(l+2-y)>>1;pos-=t;y+=t<<1;ans+=t;}
        if(pos<0||y>=r){puts("NIE");return 0;}
        pos=min(pos,(r-1-y)>>1);
    }
    printf("%d\n",ans);
}

 

相关文章:

  • 2022-12-23
  • 2022-01-09
  • 2022-01-18
  • 2021-06-13
  • 2022-03-04
  • 2021-05-16
  • 2021-08-19
  • 2021-09-17
猜你喜欢
  • 2022-01-13
  • 2021-08-29
  • 2022-03-08
  • 2021-11-26
  • 2021-10-15
  • 2021-10-12
  • 2021-12-23
相关资源
相似解决方案