File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 1176-1002.cpp
3+ * @author Macesuted (i@macesuted.moe)
4+ * @date 2025-08-01
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #define endl ' \n '
14+
15+ #define maxn 200005
16+
17+ int64_t a[maxn];
18+
19+ void solve (void ) {
20+ int n, m, k, p;
21+ cin >> n >> m >> k >> p;
22+ for (int i = 1 ; i <= n; i++) cin >> a[i];
23+
24+ auto chk = [&](int64_t lim) -> bool {
25+ int64_t sum = 0 , rest = lim * p;
26+ vector<int64_t > rec;
27+ for (int i = 1 ; i <= n; i++) {
28+ int64_t v = min (a[i], min (rest, lim) * k);
29+ if (v % k) rec.push_back (v % k), v -= v % k;
30+ sum += v, rest -= v / k;
31+ }
32+ sort (rec.begin (), rec.end (), greater<int64_t >());
33+ for (auto x : rec)
34+ if (rest) sum += x, rest--;
35+ return sum >= m;
36+ };
37+
38+ int64_t l = 0 , r = 1e9 ;
39+ while (l + 1 < r) {
40+ int64_t mid = (l + r) >> 1 ;
41+ (chk (mid) ? r : l) = mid;
42+ }
43+
44+ cout << r << endl;
45+
46+ return ;
47+ }
48+
49+ int main () {
50+ ios::sync_with_stdio (false ), cin.tie (nullptr );
51+
52+ int _ = 1 ;
53+ cin >> _;
54+ while (_--) solve ();
55+
56+ return 0 ;
57+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 1176-1005.cpp
3+ * @author Macesuted (i@macesuted.moe)
4+ * @date 2025-08-01
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #define endl ' \n '
14+
15+ void solve (void ) {
16+ int A, B, C, D;
17+ cin >> A >> B >> C >> D;
18+ int cnt[4 ];
19+ vector<int64_t > rec[4 ];
20+ for (int i = 0 ; i < 4 ; i++) {
21+ cin >> cnt[i];
22+ rec[i].push_back (0 );
23+ for (int t = 0 , x; t < cnt[i]; t++) cin >> x, rec[i].push_back (x);
24+ sort (rec[i].begin () + 1 , rec[i].end (), greater<int >());
25+ for (int t = 1 ; t <= cnt[i]; t++) rec[i][t] += rec[i][t - 1 ];
26+ }
27+
28+ int64_t ans = 0 ;
29+
30+ for (int c = 0 ; c <= min (C, cnt[2 ]); c++) {
31+ int64_t wC = rec[2 ][c];
32+ for (int d = 0 ; d <= min (D, cnt[3 ]); d++) {
33+ int64_t wD = rec[3 ][d];
34+ int nA = A + (C - c), nB = B + (C - c) + 2 * (D - d);
35+ for (int b = 0 ; b <= min (nB, cnt[1 ]); b++) {
36+ int64_t wB = rec[1 ][b];
37+ int64_t wA = rec[0 ][min (nA + 2 * (nB - b), cnt[0 ])];
38+ ans = max (ans, wA + wB + wC + wD);
39+ }
40+ }
41+ }
42+
43+ cout << ans << endl;
44+
45+ return ;
46+ }
47+
48+ int main () {
49+ ios::sync_with_stdio (false ), cin.tie (nullptr );
50+
51+ int _ = 1 ;
52+ cin >> _;
53+ while (_--) solve ();
54+
55+ return 0 ;
56+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 1176-1009.cpp
3+ * @author Macesuted (i@macesuted.moe)
4+ * @date 2025-08-01
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #define endl ' \n '
14+
15+ #define maxn 200005
16+
17+ int a[maxn], p[maxn], b[maxn];
18+
19+ void solve (void ) {
20+ int n;
21+ cin >> n;
22+ for (int i = 1 ; i <= n; i++) cin >> a[i], p[a[i]] = i;
23+ for (int i = 1 ; i <= n; i++) cin >> b[i];
24+ int ans = 1 ;
25+ for (int i = 2 ; i <= n; i++) ans += (p[b[i]] != p[b[i - 1 ]] + 1 );
26+ cout << ans << endl;
27+ return ;
28+ }
29+
30+ int main () {
31+ ios::sync_with_stdio (false ), cin.tie (nullptr );
32+
33+ int _ = 1 ;
34+ cin >> _;
35+ while (_--) solve ();
36+
37+ return 0 ;
38+ }
You can’t perform that action at this time.
0 commit comments