aboutsummaryrefslogtreecommitdiff
path: root/codeforces/RudolphAndTheAnotherCompetition
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-07-25 21:47:54 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-07-25 21:47:54 +0300
commit41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4 (patch)
tree308693614a9a51d8fd6283ee364060ca07ce647d /codeforces/RudolphAndTheAnotherCompetition
parent6b548332bfc6469756526002971c422f43f86d0a (diff)
downloadcompetitive-programming-41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4.tar.xz
competitive-programming-41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4.zip
Solved 3 problems in today's Div3 round
Diffstat (limited to 'codeforces/RudolphAndTheAnotherCompetition')
-rwxr-xr-xcodeforces/RudolphAndTheAnotherCompetition/mainbin0 -> 62544 bytes
-rwxr-xr-xcodeforces/RudolphAndTheAnotherCompetition/main.cpp196
-rw-r--r--codeforces/RudolphAndTheAnotherCompetition/main_input0.txt18
-rw-r--r--codeforces/RudolphAndTheAnotherCompetition/main_input1.txt7
-rw-r--r--codeforces/RudolphAndTheAnotherCompetition/main_input2.txt49
-rw-r--r--codeforces/RudolphAndTheAnotherCompetition/main_output0.txt5
-rw-r--r--codeforces/RudolphAndTheAnotherCompetition/main_output1.txt1
-rw-r--r--codeforces/RudolphAndTheAnotherCompetition/main_output2.txt1
8 files changed, 277 insertions, 0 deletions
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main b/codeforces/RudolphAndTheAnotherCompetition/main
new file mode 100755
index 0000000..92b0413
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main
Binary files differ
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main.cpp b/codeforces/RudolphAndTheAnotherCompetition/main.cpp
new file mode 100755
index 0000000..58246cf
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main.cpp
@@ -0,0 +1,196 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+using ll = long long;
+using pii = pair<int, int>;
+using vpi = vector<pii>;
+using vi = vector<int>;
+using vll = vector<long long>;
+using mpii = map<int, int>;
+using mpll = map<ll, ll>;
+using db = long double;
+
+#define pb push_back
+#define all(x) (x).begin(), (x).end()
+#define rall(x) (x).rbegin(), (x).rend()
+#define lb lower_bound
+#define ub upper_bound
+#define make_unique(x) \
+ sort(all((x))); \
+ (x).resize(unique(all((x))) - (x).begin())
+#define ceil(a, b) ((a) + (b) - 1) / (b))
+
+const int MOD = (int)1e9 + 7;
+const db PI = acos((db)-1);
+const int dx[4]{1, 0, -1, 0};
+const int dy[4]{0, 1, 0, -1};
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p);
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m);
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s);
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s);
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p) {
+ os << "(" << p.first << ", " << p.second << ")";
+ return os;
+}
+
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
+ os << "{";
+ for (size_t i = 0; i < vec.size(); ++i) {
+ if (i > 0)
+ os << ", ";
+ os << vec[i];
+ }
+ os << "}";
+ return os;
+}
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m) {
+ os << "{";
+ for (const auto &p : m) {
+ os << p.first << ": " << p.second << ", ";
+ }
+ os << "}";
+ return os;
+}
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m) {
+ os << "{";
+ for (const auto &p : m) {
+ os << p.first << ": " << p.second << ", ";
+ }
+ os << "}";
+ return os;
+}
+
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s) {
+ int i = 0;
+ os << "{";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
+ os << e;
+ i++;
+ }
+ os << "}";
+ return os;
+}
+
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s) {
+ int i = 0;
+ os << "{";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
+ os << e;
+ i++;
+ }
+ os << "}";
+ return os;
+}
+
+void dbg() { cerr << "\n"; }
+
+template <typename T, typename... TS> void dbg(T val, TS... vals) {
+ cerr << val << " ";
+ dbg(vals...);
+}
+
+/* stuff you should look for:
+ ---------------------------
+ * special cases (n=1?)
+ * int overflow, array bounds
+ * do smth instead of nothing and stay organized
+ * WRITE STUFF DOWN
+ * DON'T GET STUCK ON ONE APPROACH
+ */
+
+ll calc_penalty(vll &v, int b) {
+ ll penalty = 0;
+ ll pref = 0;
+ for (int i = 0; i < b; i++) {
+ pref += v[i];
+ penalty += pref;
+ }
+ return penalty;
+}
+
+int calc_problems(vll &v, int h) {
+ ll sum = 0;
+ for (int i = 0; i < v.size(); i++) {
+ if (sum + v[i] > h) {
+ return i;
+ }
+ sum += v[i];
+ }
+ return v.size();
+}
+
+struct triple {
+ int pos;
+ int first;
+ ll second;
+};
+
+// operator overloading for == for the triple struct
+bool operator==(const triple &p1, const triple &p2) {
+ return p1.first == p2.first && p1.second == p2.second;
+}
+
+ostream &operator<<(ostream &os, const triple &tr) {
+ os << "\n {" << tr.first << ' ' << tr.second << ' ' << tr.pos << "}";
+ return os;
+}
+
+bool customComparator(triple &p1, triple &p2) {
+ if (p1.first > p2.first)
+ return true;
+ else if (p1.first == p2.first && p1.second == p2.second) {
+ return p1.pos == 0;
+ } else if (p1.first == p2.first)
+ return p1.second < p2.second;
+ return false;
+}
+
+void solve() {
+ int n, m, h;
+ cin >> n >> m >> h;
+ vector<triple> mp(n);
+ for (int i = 0; i < n; i++) {
+ vll v(m);
+ for (auto &x : v) {
+ cin >> x;
+ }
+ sort(all(v));
+ int b = calc_problems(v, h);
+ ll pen = calc_penalty(v, b);
+ mp[i] = {i, b, pen};
+ }
+ sort(all(mp), customComparator);
+ for (int i = 0; i < n; i++) {
+ if (mp[i].pos == 0) {
+ cout << i + 1 << '\n';
+ }
+ }
+}
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ solve();
+ }
+}
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_input0.txt b/codeforces/RudolphAndTheAnotherCompetition/main_input0.txt
new file mode 100644
index 0000000..6b18f43
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main_input0.txt
@@ -0,0 +1,18 @@
+5
+3 3 120
+20 15 110
+90 90 100
+40 40 40
+2 1 120
+30
+30
+1 3 120
+10 20 30
+3 2 27
+8 9
+10 7
+10 8
+3 3 15
+7 2 6
+7 5 4
+1 9 8
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_input1.txt b/codeforces/RudolphAndTheAnotherCompetition/main_input1.txt
new file mode 100644
index 0000000..01faba6
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main_input1.txt
@@ -0,0 +1,7 @@
+1
+5 1 50
+1
+1
+1
+1
+1 \ No newline at end of file
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_input2.txt b/codeforces/RudolphAndTheAnotherCompetition/main_input2.txt
new file mode 100644
index 0000000..d3819c2
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main_input2.txt
@@ -0,0 +1,49 @@
+1
+47 3 129
+2 2 3
+4 1 2
+4 2 1
+3 2 4
+1 4 4
+1 2 1
+5 4 5
+6 4 5
+2 1 6
+5 5 3
+6 4 5
+4 5 6
+4 5 4
+3 6 3
+1 3 6
+2 4 4
+6 6 1
+5 6 3
+6 4 1
+1 5 2
+2 6 5
+2 6 5
+6 3 5
+1 3 4
+5 3 4
+1 1 3
+6 2 6
+2 5 4
+3 3 6
+5 4 2
+6 6 1
+6 3 2
+3 4 6
+1 1 4
+1 3 6
+2 1 4
+6 2 5
+1 6 6
+2 1 3
+4 2 6
+2 2 4
+6 5 2
+6 4 2
+6 3 6
+4 4 6
+6 5 6
+1 4 1 \ No newline at end of file
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_output0.txt b/codeforces/RudolphAndTheAnotherCompetition/main_output0.txt
new file mode 100644
index 0000000..df106a2
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main_output0.txt
@@ -0,0 +1,5 @@
+2
+1
+1
+2
+1
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_output1.txt b/codeforces/RudolphAndTheAnotherCompetition/main_output1.txt
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main_output1.txt
@@ -0,0 +1 @@
+1 \ No newline at end of file
diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_output2.txt b/codeforces/RudolphAndTheAnotherCompetition/main_output2.txt
new file mode 100644
index 0000000..9a03714
--- /dev/null
+++ b/codeforces/RudolphAndTheAnotherCompetition/main_output2.txt
@@ -0,0 +1 @@
+10 \ No newline at end of file