Submission #825615

#TimeUsernameProblemLanguageResultExecution timeMemory
825615MohamedAhmed04Arranging Tickets (JOI17_arranging_tickets)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 1e5 + 10 ; int L[MAX] , R[MAX] , C[MAX] ; int n , m ; vector< pair<int , int> >vp ; bool cmp(pair<int , int>&a , pair<int , int>&b) { if(a.second != b.second) return a.second > b.second ; else return a.first < b.first ; } int cnt[MAX] ; void Apply(pair<int , int>p) { for(int i = 1 ; i <= n ; ++i) { if(i < p.first || i >= p.second) { if(cnt[i] <= 0) return ; } } for(int i = 1 ; i <= n ; ++i) { if(i < p.first || i >= p.second) cnt[i]-- ; else cnt[i]++ ; } } bool check(int k) { for(int i = 1 ; i <= n ; ++i) cnt[i] = k ; for(auto &p : vp) { for(int i = p.first ; i < p.second ; ++i) cnt[i]-- ; } bool flag = true ; for(int i = 1 ; i <= n ; ++i) flag &= (cnt[i] >= 0) ; if(flag) return true ; for(auto &p : vp) Apply(p) ; flag = true ; for(int i = 1 ; i <= n ; ++i) flag &= (cnt[i] >= 0) ; return flag ; } int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m ; for(int i = 0 ; i < m ; ++i) { cin>>L[i]>>R[i]>>C[i] ; if(R[i] < L[i]) swap(L[i] , R[i]) ; vp.emplace_back(L[i] , R[i]) ; } sort(vp.begin() , vp.end() , cmp) ; int l = 1 , r = m ; int ans = r ; while(l <= r) { int mid = (l + r) >> 1 ; if(check(mid)) ans = mid , r = mid-1 ; else l = mid+1 ; } return cout<<ans<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...