/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
int n, m;
array<int, 3> a[N];
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; ++i){
cin >> a[i][0] >> a[i][1] >> a[i][2];
if(a[i][1] < a[i][0]) swap(a[i][0], a[i][1]);
}
sort(a+1, a+1+m, [&](const array<int, 3> &x, const array<int, 3> &y){
return pii{x[1] - x[0], x[0]} < pii{y[1] - y[0], y[0]};
});
int ans = n;
for(int k = 0; k <= m; ++k){
vector<int> cnt(n + 1);
for(int i = 1; i <= m; ++i){
if(i <= k){
for(int j = a[i][0]; j < a[i][1]; ++j) cnt[j]++;
}else{
for(int j = a[i][1]; j <= n; ++j) cnt[j]++;
for(int j = 1; j < a[i][0]; ++j) cnt[j]++;
}
}
ans = min(ans, *max_element(all(cnt)));
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |