MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Towers/soultion.cpp:15–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14using namespace std;
15int main()
16{
17 ios_base::sync_with_stdio(0);
18 cin.tie(0); cout.tie(0);
19 int n, k, ok;
20 cin >> n >> k;//we take the two inputs n and k
21 ok = k;
22 vector< pair <int, int> > vect(n), vect2;//create two vector of pairs to save the number of index in the first one and save the operated indexes in the second one
23 for (int i = 1; i <= n; i++) {
24 cin >> vect[i - 1].first;//taking input
25 vect[i - 1].second = i;//saving the index
26 }
27 while (k > 0) { //make operations maximum k number of operations
28 sort(vect.begin(), vect.end());//sort the vector every time to make the min element in the first and the max one in the last
29 if (vect[vect.size() - 1].first < vect[0].first + 2) break; //if the difference is less than two then that is the minimum difference
30 else {
31 vect[0].first++; //increase the min element by one
32 vect[vect.size() - 1].first --; //decrease the max element by one
33 k--; //decrese the num of operations allowed by one
34 vect2.push_back(make_pair(vect[vect.size() - 1].second, vect[0].second)); //save the index of the operation that we have just fifnshed to print out when we get over
35 }
36 }
37 sort(vect.begin(), vect.end());
38 cout << vect[vect.size() - 1].first - vect[0].first << " " << ok - k << endl; //printing the min difference and the number of operations we make
39 //k is the number that last after we make our operations and "ok" is the variable with the original k then the difference is the actual number of operations we have just made
40 for (int i = 0; i < vect2.size(); i++) {
41 cout << vect2[i].first << " " << vect2[i].second << endl; //printing the resulting operations we saved
42 }
43}
44//Happy Coding :))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected