#34802: 永遠停在70趴請問是哪裡寫錯了呢?


qqazwwsxeedcrrfvttgb@gmail.com (Jackis666)

學校 : 嘉義市私立輔仁高級中學
編號 : 226198
來源 : [42.73.47.160]
最後登入時間 :
2023-07-22 13:59:09
b966. 3. 線段覆蓋長度 -- 2016年3月apcs | From: [163.27.10.252] | 發表日期 : 2023-04-17 20:20

#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    long int start[N],end[N];
    for(int i=0;i<N;i++){
        cin>>start[i]>>end[i];
    } 
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++){
            if(i!=j and start[i]!=end[i]){
                if(start[i]<=end[j] and start[i]>=start[j]){
                    if(end[i]<=end[j] and end[i]>=start[j]){
                        end[i]=0;
                        start[i]=0;
                    }
                    else{
                        start[i]=end[j];
                    }
                }
                if(end[i]>start[j] and end[i]<end[j])
                    end[i]=start[j];
        }
    }
    int total=0;
    for(int i=0;i<N;i++)
        total=total+end[i]-start[i];
    cout<<total;
        
}
 

 
ZeroJudge Forum