Codeforces Round 946 (Div. 3) A B C D E G

A. Phone Desktop

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Little Rosie has a phone with a desktop (or launcher, as it is also called). The desktop can consist of several screens. Each screen is represented as a grid of size 5 × 3 5 \times 3 5×3, i.e., five rows and three columns.

There are x x x applications with an icon size of 1 × 1 1 \times 1 1×1 cells; such an icon occupies only one cell of the screen. There are also y y y applications with an icon size of 2 × 2 2 \times 2 2×2 cells; such an icon occupies a square of 4 4 4 cells on the screen. Each cell of each screen can be occupied by no more than one icon.

Rosie wants to place the application icons on the minimum number of screens. Help her find the minimum number of screens needed.

Input

The first line of the input contains t t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1t104) — the number of test cases.

The first and only line of each test case contains two integers x x x and y y y ( 0 ≤ x , y ≤ 99 0 \leq x, y \leq 99 0x,y99) — the number of applications with a 1 × 1 1 \times 1 1×1 icon and the number of applications with a 2 × 2 2 \times 2 2×2 icon, respectively.

Output

For each test case, output the minimal number of required screens on a separate line.

Example

i n p u t \tt input input
11
1 1
7 2
12 4
0 3
1 0
8 1
0 0
2 0
15 0
8 2
0 9
o u t p u t \tt output output
1
1
2
2
1
1
0
1
1
2
5

Note

The solution for the first test case can look as follows:

Blue squares represent empty spaces for icons, green squares represent 1 × 1 1 \times 1 1×1​ icons, red squares represent 2 × 2 2 \times 2 2×2​ icons

The solution for the third test case can look as follows:

Tutorial

由题意得,每个屏幕最多可以容纳 2 2 2 2 × 2 2 \times 2 2×2 图标,所以可以通过大图标先找出需要至少多少个屏幕,最后看看 1 × 1 1 \times 1 1×1 的图标能不能全部塞到这些屏幕里,如果不可以则可以拿新屏幕全部塞下 1 × 1 1 \times 1 1×1 的图标

此解法时间复杂度为 O ( 1 ) \mathcal O(1) O(1)

Solution

package main

import (
	"bufio"
	. "fmt"
	"os"
)

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve() {
	var x, y int
	Fscan(in, &x, &y)
	ans := (y + 1) / 2
	ans += (max(0, x - (ans * 5 * 3 - y * 4)) + 14) / 15
	Println(ans)
}

func main() {
	defer out.Flush()
	var Test int
	Fscanf(in, "%d\n", &Test)
	for tt := 0; tt < Test; tt++ {
		solve()
	}
}

B. Symmetric Encoding

time limit per test: 2 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Polycarp has a string s s s, which consists of lowercase Latin letters. He encodes this string using the following algorithm:

  • first, he constructs a new auxiliary string r r r, which consists of all distinct letters of the string s s s, written in alphabetical order;
  • then the encoding happens as follows: each character in the string s s s is replaced by its symmetric character from the string r r r (the first character of the string r r r will be replaced by the last, the second by the second from the end, and so on).

For example, encoding the string s s s=“codeforces” happens as follows:

  • the string r r r is obtained as “cdefors”;
  • the first character s 1 s_1 s1=‘c’ is replaced by ‘s’;
  • the second character s 2 s_2 s2=‘o’ is replaced by ‘e’;
  • the third character s 3 s_3 s3=‘d’ is replaced by ‘r’;
  • the last character s 10 s_{10} s10=‘s’ is replaced by ‘c’.

The string r r r and replacements for s s s=“codeforces”.

Thus, the result of encoding the string s s s=“codeforces” is the string “serofedsoc”.

Write a program that performs decoding — that is, restores the original string s s s from the encoding result.

Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105) — the length of the string b b b.

The second line of each test case contains a string b b b of length n n n, consisting of lowercase Latin letters — the result of encoding the original string s s s.

It is guaranteed that the sum of the values of n n n over all test cases in the test does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, output the string s s s from which the encoding result b b b was obtained.

Example

i n p u t \tt input input
5
10
serofedsoc
3
ttf
9
tlrhgmaoi
1
w
15
hnndledmnhlttin
o u t p u t \tt output output
codeforces
fft
algorithm
w
meetinthemiddle

Tutorial

直接将字符串里包含的字符全部取出进行排序去重,然后根据题意一一对应,最后将原字符串一一映射即可

此解法时间复杂度为 O ( n log ⁡ n ) \mathcal O(n \log n) O(nlogn),即排序所需要的时间

Solution

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long

void solve() {
    int n;
    string s;
    cin >> n >> s;
    string mid = s;
    map<char, char> mp;
    ranges::sort(mid);
    mid.erase(unique(mid.begin(), mid.end()), mid.end());
    for (int i = 0; i < mid.size(); ++i) {
        mp[mid[i]] = mid[mid.size() - i - 1];
    }
    for (char &si : s) {
        si = mp[si];
    }
    cout << s << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int Test; cin >> Test; while (Test--)
    solve();
    return 0;
}

C. Beautiful Triple Pairs

time limit per test: 4 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Polycarp was given an array a a a of n n n integers. He really likes triples of numbers, so for each j j j ( 1 ≤ j ≤ n − 2 1 \le j \le n - 2 1jn2) he wrote down a triple of elements [ a j , a j + 1 , a j + 2 ] [a_j, a_{j + 1}, a_{j + 2}] [aj,aj+1,aj+2].

Polycarp considers a pair of triples b b b and c c c beautiful if they differ in exactly one position, that is, one of the following conditions is satisfied:

  • b 1 ≠ c 1 b_1 \ne c_1 b1=c1 and b 2 = c 2 b_2 = c_2 b2=c2 and b 3 = c 3 b_3 = c_3 b3=c3;
  • b 1 = c 1 b_1 = c_1 b1=c1 and b 2 ≠ c 2 b_2 \ne c_2 b2=c2 and b 3 = c 3 b_3 = c_3 b3=c3;
  • b 1 = c 1 b_1 = c_1 b1=c1 and b 2 = c 2 b_2 = c_2 b2=c2 and b 3 ≠ c 3 b_3 \ne c_3 b3=c3.

Find the number of beautiful pairs of triples among the written triples [ a j , a j + 1 , a j + 2 ] [a_j, a_{j + 1}, a_{j + 2}] [aj,aj+1,aj+2].

Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

The first line of each test case contains a single integer n n n ( 3 ≤ n ≤ 2 ⋅ 1 0 5 3 \le n \le 2 \cdot 10^5 3n2105) — the length of the array a a a.

The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 6 1 \le a_i \le 10^6 1ai106) — the elements of the array.

It is guaranteed that the sum of the values of n n n for all test cases in the test does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, output a single integer — the number of beautiful pairs of triples among the pairs of the form [ a j , a j + 1 , a j + 2 ] [a_j, a_{j + 1}, a_{j + 2}] [aj,aj+1,aj+2].

Note that the answer may not fit into 32-bit data types.

Example

i n p u t \tt input input
8
5
3 2 2 2 3
5
1 2 1 2 1
8
1 2 3 2 2 3 4 2
4
2 1 1 1
8
2 1 1 2 1 1 1 1
7
2 1 1 1 1 1 1
6
2 1 1 1 1 1
5
2 1 1 1 1
o u t p u t \tt output output
2
0
3
1
8
4
3
2

Note

In the first example, a = [ 3 , 2 , 2 , 2 , 3 ] a = [3, 2, 2, 2, 3] a=[3,2,2,2,3], Polycarp will write the following triples:

  1. [ 3 , 2 , 2 ] [3, 2, 2] [3,2,2];
  2. [ 2 , 2 , 2 ] [2, 2, 2] [2,2,2];
  3. [ 2 , 2 , 3 ] [2, 2, 3] [2,2,3].

The beautiful pairs are triple 1 1 1 with triple 2 2 2 and triple 2 2 2 with triple 3 3 3.

In the third example, a = [ 1 , 2 , 3 , 2 , 2 , 3 , 4 , 2 ] a = [1, 2, 3, 2, 2, 3, 4, 2] a=[1,2,3,2,2,3,4,2], Polycarp will write the following triples:

  1. [ 1 , 2 , 3 ] [1, 2, 3] [1,2,3];
  2. [ 2 , 3 , 2 ] [2, 3, 2] [2,3,2];
  3. [ 3 , 2 , 2 ] [3, 2, 2] [3,2,2];
  4. [ 2 , 2 , 3 ] [2, 2, 3] [2,2,3];
  5. [ 2 , 3 , 4 ] [2, 3, 4] [2,3,4];
  6. [ 3 , 4 , 2 ] [3, 4, 2] [3,4,2];

The beautiful pairs are triple 1 1 1 with triple 4 4 4, triple 2 2 2 with triple 5 5 5, and triple 3 3 3 with triple 6 6 6.

Tutorial

设三元组的三个数分别为 a , b , c a, b, c a,b,c,用四个字典 c n t 1 , c n t 2 , c n t 3 , c n t 4 cnt_1, cnt_2, cnt_3, cnt_4 cnt1,cnt2,cnt3,cnt4 分别记录 { a , b } , { a , c } , { b , c } , { a , b , c } \{a, b\}, \{a, c\}, \{b, c\}, \{a, b, c\} {a,b},{a,c},{b,c},{a,b,c} 的出现次数,则对于每个三元组,其对答案的贡献为在此之前 { a , b } \{a, b\} {a,b} 出现的次数 + { a , c } +\{a, c\} +{a,c} 出现的次数 + { b , c } +\{b, c\} +{b,c} 出现的次数 − 3 × { a , b , c } -3 \times \{a, b, c\} 3×{a,b,c} 出现的次数,即 c n t 1 [ ( a , b ) ] + c n t 2 [ ( a , c ) ] + c n t 3 [ ( b , c ) ] − 3 × c n t 4 [ ( a , b , c ) ] cnt_1[(a, b)] + cnt_2[(a, c)] + cnt_3[(b, c)] - 3 \times cnt_4[(a, b, c)] cnt1[(a,b)]+cnt2[(a,c)]+cnt3[(b,c)]3×cnt4[(a,b,c)]

此算法时间复杂度为 O ( n ) \mathcal O(n) O(n)

Solution

import sys
from collections import defaultdict
input = lambda: sys.stdin.readline().strip()

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    cnt1 = defaultdict(int)
    cnt2 = defaultdict(int)
    cnt3 = defaultdict(int)
    cnt4 = defaultdict(int)
    ans = 0
    for i in range(n - 2):
        x, y, z = a[i : i + 3]
        ans += cnt1[(x, y)] + cnt2[(x, z)] + cnt3[(y, z)] - 3 * cnt4[(x, y, z)]
        cnt1[(x, y)] += 1
        cnt2[(x, z)] += 1
        cnt3[(y, z)] += 1
        cnt4[(x, y, z)] += 1
    print(ans)

D. Ingenuity-2

time limit per test: 2 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Let’s imagine the surface of Mars as an infinite coordinate plane. Initially, the rover Perseverance-2 and the helicopter Ingenuity-2 are located at the point with coordinates ( 0 , 0 ) (0, 0) (0,0). A set of instructions s s s consisting of n n n instructions of the following types was specially developed for them:

  • N: move one meter north (from point ( x , y ) (x, y) (x,y) to ( x , y + 1 ) (x, y + 1) (x,y+1));
  • S: move one meter south (from point ( x , y ) (x, y) (x,y) to ( x , y − 1 ) (x, y - 1) (x,y1));
  • E: move one meter east (from point ( x , y ) (x, y) (x,y) to ( x + 1 , y ) (x + 1, y) (x+1,y));
  • W: move one meter west (from point ( x , y ) (x, y) (x,y) to ( x − 1 , y ) (x - 1, y) (x1,y)).

Each instruction must be executed either by the rover or by the helicopter. Moreover, each device must execute at least one instruction. Your task is to distribute the instructions in such a way that after executing all n n n instructions, the helicopter and the rover end up at the same point, or determine that this is impossible.

Input

The first line of input contains t t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1t104) — the number of test cases.

The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105) — the number of instructions.

The second line of each test case contains a string s s s of length n n n consisting of the characters ‘N’, ‘S’, ‘E’, ‘W’ — the sequence of instructions.

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10 ^ 5 2105.

Output

For each test case, if the required distribution of instructions exists, output a string p p p of length n n n consisting of the characters ‘R’, ‘H’. If the i i i-th operation should be executed by the rover, then p i = R p_i=\text{R} pi=R, if the i i i-th operation should be executed by the helicopter, then p i = H p_i=\text{H} pi=H. If there are multiple solutions, output any of them.

Otherwise, output NO.

Example

i n p u t \tt input input
10
6
NENSNE
3
WWW
6
NESSWS
2
SN
2
WE
4
SSNN
4
WESN
2
SS
4
EWNN
4
WEWE
o u t p u t \tt output output
RRHRRH
NO
HRRHRH
NO
NO
RHRH
RRHH
RH
RRRH
RRHH

Note

Let’s consider the first example: the string S = NENSNE S = \texttt{NENSNE} S=NENSNE. One of the possible solutions, shown in the figure below, is p = RRHRRH p = \texttt{RRHRRH} p=RRHRRH, using which both the rover and the helicopter will end up one meter north and one meter east.

For WWW, the solution is impossible.

Tutorial

对于两个的方向,我们可以选取 NE 为正方向,SW 为负方向,然后遍历字符串进行计数,最后根据计数判断 r o v e r rover rover h e l i c o p t e r helicopter helicopter 需要在哪个方向走多少步

如果两个相反的方向计数为奇数,则不能达到要求,输出 NO

否则判断 r o v e r rover rover h e l i c o p t e r helicopter helicopter 需要多走多少步或少走多少步,最后判断是否双方都至少移动了一次,如果只有一个人进行了移动,即答案全为 H 或全为 R,则不能达到要求,输出 NO

此解法时间复杂度为 O ( n ) \mathcal O(n) O(n)

Solution

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int cnt_N = 0, cnt_E = 0;
    for (char c : s) {
        if (c == 'N') {
            ++cnt_N;
        } else if (c == 'S') {
            --cnt_N;
        } else if (c == 'E') {
            ++cnt_E;
        } else {
            --cnt_E;
        }
    }
    if (cnt_N & 1 or cnt_E & 1) {
        cout << "NO" << endl;
        return;
    }
    string ans(n, 'R');
    cnt_N /= 2;
    cnt_E /= 2;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'N' and cnt_N > 0) {
            --cnt_N;
            ans[i] = 'H';
        } else if (s[i] == 'S' and cnt_N < 0) {
            ++cnt_N;
            ans[i] = 'H';
        } else if (s[i] == 'E' and cnt_E > 0) {
            --cnt_E;
            ans[i] = 'H';
        } else if (s[i] == 'W' and cnt_E < 0) {
            ++cnt_E;
            ans[i] = 'H';
        }
    }
    if (ans.find('R') != -1 and ans.find('H') != -1) {
        cout << ans << endl;
        return;
    }
    int W = s.find('W'), E = s.find('E'), N = s.find('N'), S = s.find('S');
    if (N != -1 and S != -1) {
        ans[N] = ans[S] = 'H';
    } else if (W != -1 and E != -1) {
        ans[W] = ans[E] = 'H';
    }
    if (ans.find('R') != -1 and ans.find('H') != -1) {
        cout << ans << endl;
    } else {
        cout << "NO" << endl;
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int Test; cin >> Test; while (Test--)
    solve();
    return 0;
}

E. Money Buys Happiness

time limit per test: 3 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Being a physicist, Charlie likes to plan his life in simple and precise terms.

For the next m m m months, starting with no money, Charlie will work hard and earn x x x pounds per month. For the i i i-th month ( 1 ≤ i ≤ m ) (1 \le i \le m) (1im), there’ll be a single opportunity of paying cost c i c_i ci pounds to obtain happiness h i h_i hi.

Borrowing is not allowed. Money earned in the i i i-th month can only be spent in a later j j j-th month ( j > i j > i j>i).

Since physicists don’t code, help Charlie find the maximum obtainable sum of happiness.

Input

The first line of input contains a single integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1t1000) — the number of test cases.

The first line of each test case contains two integers, m m m and x x x ( 1 ≤ m ≤ 50 1 \le m \le 50 1m50, 1 ≤ x ≤ 1 0 8 1 \le x \le 10^8 1x108) — the total number of months and the monthly salary.

The i i i-th of the following m m m lines contains two integers, c i c_i ci and h i h_i hi ( 0 ≤ c i ≤ 1 0 8 0 \le c_i \le 10^8 0ci108, 1 ≤ h i ≤ 1 0 3 1 \le h_i \le 10^3 1hi103) — the cost and happiness on offer for the i i i-th month. Note that some happiness may be free ( c i = 0 c_i=0 ci=0 for some i i i’s).

It is guaranteed that the sum of ∑ i h i \sum_i h_i ihi over all test cases does not exceed 1 0 5 10^5 105.

Output

For each test case, print a single integer, the maximum sum of happiness Charlie could obtain.

Example

i n p u t \tt input input
7
1 10
1 5
2 80
0 10
200 100
3 100
70 100
100 200
150 150
5 8
3 1
5 3
3 4
1 5
5 3
2 5
1 5
2 1
5 3
2 5
2 4
4 1
5 1
3 4
5 2
2 1
1 2
3 5
3 2
3 2
o u t p u t \tt output output
0
10
200
15
1
9
9

Note

In the first test case, Charlie only gets paid at the end of the month, so is unable to afford anything.

In the second test case, Charlie obtains the free happiness in the first month.

In the third test case, it’s optimal for Charlie to buy happiness in the second month. Even with money left at the end, Charlie could not go back in time to obtain the happiness on offer in the first month.

Tutorial

这其实是一道经典背包 d p dp dp问题,但需要在原来的基础上改变一下,可以将支付的成本 c i c_i ci 看作物品价值,将幸福感 h i h_i hi 看作物品体积,将 d p h i dp_{h_i} dphi 看作背包容量,只要当前物品幸福度 h j h_j hj 满足 d p j − c i + h i ≤ i ∗ x dp_{j - c_i} + h_i \leq i * x dpjci+hiix 即可更新 d p h i dp_{h_i} dphi 最小值,最后从最大背包容量逆序遍历,第一个可以支付的幸福感就是答案

此解法时间复杂度为 O ( m ⋅ ∑ h i ) \mathcal O(m \cdot \sum h_i) O(mhi)

Solution

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define endl '\n'
#define int long long
#define PII pair<int, int>

const int INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7; // 998244353;

void solve() {
    int m, x, mx = 0;
    cin >> m >> x;
    vector<PII> a(m);
    for (PII &ai : a) {
        cin >> ai.ff >> ai.ss;
        mx += ai.ss;
    }
    vector<int> dp(mx + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < m; ++i) {
        for (int j = mx; j >= a[i].ss; --j) {
            if (dp[j - a[i].ss] + a[i].ff <= i * x) {
                dp[j] = min(dp[j], dp[j - a[i].ss] + a[i].ff);
            }
        }
    }
    for (int i = mx; ~i; --i) {
        if (dp[i] != INF) {
            cout << i << endl;
            return;
        }
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(15);
    time_t begin = clock();
    int Test; cin >> Test; while (Test--)
    solve();
    time_t end = clock();
    double solve_time = double(end - begin) / CLOCKS_PER_SEC;
    // cout << "runtime: " << solve_time << endl;
    return 0;
}

G. Money Buys Less Happiness Now

time limit per test: 2 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

You can never buy enough happiness, so here we go again! In this version, you can only buy h i = 1 h_i = 1 hi=1 unit of happiness each month, but the number of months is hugely increased. We are in the realm of quantum happiness and time dilation.

Being a physicist, Charlie likes to plan his life in simple and precise terms.

For the next m m m months, starting with no money, Charlie will work hard and earn x x x pounds per month. For the i i i-th month ( 1 ≤ i ≤ m ) (1 \le i \le m) (1im), there’ll be a single opportunity of paying cost c i c_i ci pounds to obtain one unit of happiness. You cannot buy more than one unit each month.

Borrowing is not allowed. Money earned in the i i i-th month can only be spent in a later j j j-th month ( j > i j>i j>i).

Since physicists don’t code, help Charlie find the maximum reachable units of happiness.

Input

The first line of the input contains t t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1t104) — the number of test cases.

The first line of each test case contains two integers, m m m and x x x ( 1 ≤ m ≤ 2 ⋅ 1 0 5 1 \le m \le 2 \cdot 10^5 1m2105, 1 ≤ x ≤ 1 0 3 1 \le x \le 10^3 1x103) — the total number of months and the monthly salary.

The second line of each test case contains m m m integers c 1 , c 2 , … , c m c_1, c_2, \dots, c_m c1,c2,,cm ( 1 ≤ c i ≤ 1 0 3 1 \leq c_i \leq 10^3 1ci103) — the cost of one unit of happiness for each month.

It is guaranteed that sum of m m m over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, output one integer — the maximal amount of happiness Charlie can get.

Example

i n p u t \tt input input
6
3 3
2 2 2
6 5
2 2 8 2 6 8
6 4
4 10 3 8 6 10
2 1
1 1
4 1
4 1 3 1
4 2
1 3 4 3
o u t p u t \tt output output
2
4
3
1
2
1

Tutorial

反悔贪心,直接按顺序遍历即可,如果此时可以获得幸福感,就获得幸福感,如果不能,就看在此之前有没有花更多的钱来获得幸福感,如果有则说明那一次获取幸福感是错误的,此时丢弃在此之前获得的幸福感,用更少的钱获得同样的幸福感

用优先队列即可知道之前花的最多的钱是什么

此解法时间复杂度为 O ( n ) \mathcal O(n) O(n)

Solution

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long

void solve() {
    int m, x, money = 0;
    cin >> m >> x;
    priority_queue<int> q;
    for (int i = 0; i < m; ++i) {
        int c;
        cin >> c;
        if (c <= money) {
            money -= c;
            q.emplace(c);
        } else if (q.size() and q.top() >= c) {
            money += q.top() - c;
            q.pop();
            q.emplace(c);
        }
        money += x;
    }
    cout << q.size() << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(15);
    time_t begin = clock();
    int Test; cin >> Test; while (Test--)
    solve();
    time_t end = clock();
    double solve_time = double(end - begin) / CLOCKS_PER_SEC;
    // cout << "runtime: " << solve_time << endl;
    return 0;
}
  • 40
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值