#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 1;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define ll long long
#define pb push_back
using namespace std;
#define int ll
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, m;
cin >> n >> m;
int addToIt = 0;
vector<pair<int, int>> v(m);
map<pair<int, int>, int> mp;
rep(i, 0, m) {
int a, b, c;
cin >> a >> b >> c;
a--; b--;
mp[{a, b}] += c;
}
repIn2(ab, cnt, mp) {
addToIt += cnt / 2;
if(cnt % 2) v.pb(ab);
}
int ans = 1e9;
m = v.size();
rep(mask, 0, 1 << m) {
vector<int> cnt(n);
rep(i, 0, m) {
auto [l, r] = v[i];
if(l > r) swap(l, r);
if(mask & (1 << i)) rep(j, l, r) cnt[j]++;
else rep(j, r, l + n) cnt[j % n]++;
}
int mx = 0;
rep(i, 0, n) mx = max(mx, cnt[i]);
ans = min(ans, mx);
}
cout << ans + addToIt << '\n';
}
# | 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... |