File tree 2 files changed +119
-0
lines changed
2022/Contests/Div 2/778/Programs
2 files changed +119
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < algorithm>
4
+ #include < set>
5
+
6
+ using namespace std ;
7
+
8
+ void solve ()
9
+ {
10
+ int no_of_elements;
11
+ cin >> no_of_elements;
12
+
13
+ long long sum = 0 , minimum = 1e12 , maximum = 0 ;
14
+ multiset <long long > S, original_S;
15
+ vector <long long > A (no_of_elements + 1 );
16
+ for (int i = 1 ; i <= no_of_elements; i++)
17
+ {
18
+ cin >> A[i];
19
+
20
+ original_S.insert (A[i]);
21
+
22
+ sum += A[i];
23
+ minimum = min (minimum, A[i]);
24
+ maximum = max (maximum, A[i]);
25
+ }
26
+
27
+ S.insert (sum);
28
+
29
+ int possible = true ;
30
+ while (S.size () > 0 && *(S.begin ()) >= minimum && *(S.rbegin ()) >= *(original_S.rbegin ()))
31
+ {
32
+ auto it1 = (S.rbegin ());
33
+ long long x = *it1;
34
+
35
+ if (original_S.count (x) > 0 )
36
+ {
37
+ original_S.erase (original_S.find (x));
38
+ S.erase (S.find (x));
39
+
40
+ continue ;
41
+ }
42
+
43
+ S.erase (S.find (x));
44
+ long long new_x = x/2 , new_y = x/2 + (x%2 != 0 );
45
+
46
+
47
+ S.insert (new_x);
48
+ S.insert (new_y);
49
+ }
50
+
51
+ possible = (S.size () == 0 );
52
+
53
+ cout << (possible ? " YES" : " NO" ) << " \n " ;
54
+ }
55
+
56
+ int main ()
57
+ {
58
+ ios_base::sync_with_stdio (false );
59
+ cin.tie (NULL );
60
+
61
+ int no_of_test_cases;
62
+ cin >> no_of_test_cases;
63
+
64
+ while (no_of_test_cases--)
65
+ solve ();
66
+
67
+ return 0 ;
68
+ }
69
+
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < algorithm>
4
+
5
+ using namespace std ;
6
+
7
+ void solve ()
8
+ {
9
+ string S;
10
+ cin >> S;
11
+
12
+ const int NO_OF_ALPHABETS = 26 ;
13
+ vector <int > frequency (NO_OF_ALPHABETS + 1 , 0 );
14
+ for (int i = 0 ; i < S.size (); i++)
15
+ {
16
+ frequency[S[i] - ' a' ]++;
17
+ }
18
+
19
+ int start = 0 ;
20
+ for (int i = 0 ; i < S.size (); i++)
21
+ {
22
+ if (frequency[S[i] - ' a' ] == 1 )
23
+ {
24
+ start = i;
25
+ break ;
26
+ }
27
+
28
+ frequency[S[i] - ' a' ]--;
29
+ }
30
+
31
+ string answer;
32
+ for (int i = start; i < S.size (); i++)
33
+ {
34
+ answer += S[i];
35
+ }
36
+
37
+ cout << answer << " \n " ;
38
+ }
39
+
40
+ int main ()
41
+ {
42
+ int no_of_test_cases;
43
+ cin >> no_of_test_cases;
44
+
45
+ while (no_of_test_cases--)
46
+ solve ();
47
+
48
+ return 0 ;
49
+ }
50
+
You can’t perform that action at this time.
0 commit comments