#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii ;
typedef pair<ll, ll> pll ;
typedef vector<pii> vii ;
typedef vector<int> veci ;
typedef vector<pll> vll ;
typedef vector<ll> vecll;
// find_by_order order_of_key
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define lb lower_bound
#define ub upper_bound
#define for1(n) for(int i=1;i<=n;i++)
#define for0(n) for(int i=0;i<n;i++)
#define forn(n) for(int i=n;i>0;i--)
#define pq priority_queue <pii, vector<pii>, greater<pii>>
const int N=3e3+3;
int n,m,k,q;
vector<int>g[N];
bool check(int t,int x){
int tt=t;
multiset<int>C,D;
for1(n){
while(C.size() && (*C.begin())==i)
C.erase(C.begin());
while(D.size() && (*D.begin())==i)
D.erase(D.begin());
for(int x:g[i])C.insert(x);
while(t+int(C.size())-int(D.size())>x){
auto it=C.end();it--;
D.insert((*it));
C.erase(it);
tt--;
}
}
return (tt>=0);
}
int solve(int t){
int l=t-1,r=m;
while(r-l!=1){
int mid=(l+r)>>1;
if(check(t,mid)==0)l=mid;
else r=mid;
}
return l+1;
}
int main(){
fast_io
cin>>n>>m;
for1(m){
int a,b,c;cin>>a>>b>>c;
if(a>b)swap(a,b);
g[a].pb(b);
}
int ans=m;
for0(m)ans=min(ans,solve(i));
cout<<ans<<endl;
}
| # | 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... |