// Problem: Restoring the Duration of Tasks // Contest: Codeforces // URL: https://m1.codeforces.com/contest/1690/problem/C // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)
/* Name: Author: xiaruize Date: */ #include<bits/stdc++.h> usingnamespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double constint INF = 0x3f3f3f3f; constint MOD = 1000000007; constint N = 2e5 + 10;
// bool st; int t; int n; int s[N], f[N]; // bool en;
voidsolve() { cin >> n; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) cin >> f[i]; int now = 0; for (int i = 1; i <= n; i++) { now = max(now, s[i]); cout << f[i] - now << ' '; now = f[i]; } cout << endl; return; }
// Problem: Black and White Stripe // Contest: Codeforces // URL: https://m1.codeforces.com/contest/1690/problem/D // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)
/* Name: Author: xiaruize Date: */ #include<bits/stdc++.h> usingnamespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double constint INF = 0x3f3f3f3f; constint MOD = 1000000007; constint N = 2e5 + 10;
// bool st; int n, t, k; string s; int sum[N]; // bool en;
voidsolve() { cin >> n >> k; cin >> s; sum[0] = 0; for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (s[i - 1] == 'W' ? 1 : 0); int res = k; for (int i = k; i <= n; i++) { res = min(res, sum[i] - sum[i - k]); } cout << res << endl; }
// Problem: Price Maximization // Contest: Codeforces // URL: https://m1.codeforces.com/contest/1690/problem/E // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)
/* Name: Author: xiaruize Date: */ #include<bits/stdc++.h> usingnamespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double constint INF = 0x3f3f3f3f; constint MOD = 1000000007; constint N = 2e5 + 10;
// bool st; int t; int n, k, x; int cnt[1005]; int sum = 0, res = 0; // bool en;
voidsolve() { memset(cnt, 0, sizeof(cnt)); scanf("%lld%lld", &n, &k); sum = res = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &x); cnt[x % k]++; res += x / k; } int l = 0, r = k - 1; while (l <= r) { if (l + r < k) l++; if (l > r) break; if (l == r && l + r >= k) { sum += cnt[l] / 2; cnt[l] &= 1; break; } if (cnt[l] < cnt[r]) { sum += cnt[l]; cnt[r] -= cnt[l++]; } else { sum += cnt[r]; cnt[l] -= cnt[r--]; } } printf("%lld\n", res + sum); }