-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
61 lines (49 loc) · 1.29 KB
/
Copy pathtemplate.cpp
File metadata and controls
61 lines (49 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define en '\n'
// Fast I/O
void fast_io() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
// Comparator for sorting vector of pairs
bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
// Example: Sort by first ascending, then second descending
if (a.first == b.first)
return a.second > b.second;
return a.first < b.first;
}
int main() {
fast_io();
ll tc;
cin >> tc; // Number of test cases
while (tc--) {
ll n;
cin >> n; // Number of elements
vector<ll> arr(n);
for (ll i = 0; i < n; ++i) {
cin >> arr[i]; // Input array
}
// Example: Sort array (ascending)
sort(arr.begin(), arr.end());
// Output array
for (ll i = 0; i < n; ++i) {
cout << arr[i] << ' ';
}
cout << en;
// Example: Vector of pairs input
vector<pair<ll, ll>> vp(n);
for (ll i = 0; i < n; ++i) {
cin >> vp[i].first >> vp[i].second;
}
// Sort pairs with custom comparator
sort(vp.begin(), vp.end(), cmp);
// Output sorted pairs
for (auto &p : vp) {
cout << p.first << ' ' << p.second << en;
}
}
return 0;
}