Skip to content

Instantly share code, notes, and snippets.

@exoad
Last active January 7, 2022 23:52
Show Gist options
  • Save exoad/2cd3c740725dd78d7dd89465a1b07db6 to your computer and use it in GitHub Desktop.
Save exoad/2cd3c740725dd78d7dd89465a1b07db6 to your computer and use it in GitHub Desktop.
All rank POTD #1 Q1
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using mviip = vector<pair<int, int>>;
#define FOR(n) for(int i =1; i <= n; i++)
#define FORB(x, n) for(int i = x; i < n; i++)
#define pb push_back
const int MAX = 1e5 + 10;
int a[MAX];
ll sum;
int main() {
// read input
int n;
cin >> n;
FOR(n) {
cin >> a[i];
sum += a[i];
}
mviip bruh;
sort(a + 1, a+1+n);
// this loop gets our positive number in the list (our first number)
FORB(2, n) {
// we now do the operation to find our second number
if(a[i] > 0) {
bruh.pb({a[1], a[i]});
a[1] -= a[i];
}
}
bruh.pb({a[n], a[1]});
a[n] -= a[1];
FORB(2, n) {
if(a[i] <= 0) {
bruh.pb({a[n], a[i]});
a[n] -= a[i];
}
}
// now we can print out our answers, first we print our biggest value
cout << (a[n]) << "\n";
// then we print out our operations
for(auto e : bruh) {
cout << e.first << " " << e.second << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment