b966. 第 3 題 線段覆蓋長度 - 高中生程式解題系統
本文最後更新於:2024年1月18日 下午
Zerojudge
解題紀錄
b966. 第 3 題 線段覆蓋長度 - 高中生程式解題系統
// Author : ysh
// 2024/01/18 Thu 17:02:49
#include<bits/stdc++.h>
using namespace std;
#include<slow>
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<pair<int,int>>f(n);
cin>>f;
sort(all(f));
int l = -1,r = -1;
int ans = 0;
repo(&i,f) {
if(i.first > r) {
ans = ans + (r - l);
l = i.first;
r = i.second;
}
r = max(r,i.second);
}
ans = ans + (r - l);
cout<<ans;
return 0;
}
b966. 第 3 題 線段覆蓋長度 - 高中生程式解題系統
http://mysh212.github.io/algosolution/Zerojudge-b966-2.cpp/