Submission #5926269


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int a[100005];

vii c,nc;
vector<pii> v;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,0,n-1)cin>>a[i];
sort(a,a+n);

c.pb(a[0]);

rep(i,1,n-1)
{
	if(a[i]>0)nc.pb(a[i]);
	else c.pb(a[i]);
}

int szc=c.size(),szn=nc.size();

int mn=min(c.size(),nc.size());

int ans=0;

if(szc>=szn)
{
	ans=nc[0]-c[0];
	v.pb(mp(nc[0],c[0]));
}
else
{
	ans=c[0]-nc[0];
	v.pb(mp(c[0],nc[0]));
}

rep(i,1,mn-1)
{
	v.pb(mp(c[i],ans));
	ans=c[i]-ans;
	if(i==mn-1&&szc<szn)
	{
		v.pb(mp(ans,nc[i]));
		ans=ans-nc[i];
	}
	else
	{
		v.pb(mp(nc[i],ans));
		ans=nc[i]-ans;
	}
}

if(szc>=szn)
{
	rep(i,mn,szc-1)
	{
		v.pb(mp(ans,c[i]));
		ans-=c[i];
	}
}
else
{
	rep(i,mn,szn-2)
	{
		v.pb(mp(ans,nc[i]));
		ans-=nc[i];
	}
	v.pb(mp(nc[szn-1],ans));
	ans=nc[szn-1]-ans;
}
ol(ans);on;
tr(v,it)
{
	o2(it->ff,it->ss);on;
}

return 0;
}

Submission Info

Submission Time
Task C - Successive Subtraction
User abisheka
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2256 Byte
Status
Exec Time 111 ms
Memory 3828 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
× 2
× 17
× 5
× 4
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt 3 ms 512 KB
02.txt 3 ms 512 KB
03.txt 3 ms 512 KB
04.txt 3 ms 512 KB
05.txt 3 ms 512 KB
06.txt 33 ms 3448 KB
07.txt 33 ms 3448 KB
08.txt 32 ms 3316 KB
09.txt 31 ms 3188 KB
10.txt 34 ms 3452 KB
11.txt 34 ms 3828 KB
12.txt 34 ms 3508 KB
13.txt 107 ms 1276 KB
14.txt 33 ms 3444 KB
15.txt 33 ms 3444 KB
16.txt 29 ms 3252 KB
17.txt 34 ms 3444 KB
18.txt 33 ms 3444 KB
19.txt 33 ms 3444 KB
20.txt 110 ms 1276 KB
21.txt 111 ms 1276 KB
22.txt 29 ms 3572 KB
23.txt 30 ms 3572 KB
24.txt 96 ms 256 KB
s1.txt 1 ms 256 KB
s2.txt 1 ms 256 KB