Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

bad test cases
Author: Night Fox
ID: 060233
Problem: 138
Contest: 0
Date: 2013-11-10 18:36:40

this code can answer your tests and can accept your problem:

#include<iostream>
#include<algorithm>
using namespace std;

#define F first
#define S second

const int MAXN=10000+10;

int n;
int t;
int x;
pair <int,int> a[MAXN];
int b[MAXN][2];

void input()
{
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].F;
a[i].S=i;
t+=a[i].F;
}
t/=2;
for(int i=0;i<t;i++)
b[i][1]=-1;
}

void solve()
{
sort(a,a+n);
int s=0,p=0;
for(int i=n-1;i>=0;i--){
if(s<t && a[i].F!=1){
while(s<t && a[i].F>1){
b[s][0]=a[i].S;
a[i].F--;
s++;
}
if(a[i].F==1 && s<t){
b[s][1]=a[i].S;
a[i].F--;
}
else{
while(a[i].F>0){
if(b[x][1]==-1){
b[x][1]=a[i].S;
a[i].F--;
}
x++;
}
}
}
else
while(a[i].F>0){
if(b[p][1]==-1){
b[p][1]=a[i].S;
a[i].F--;
}
p++;
}
}
cout<<t<<endl;
for(int i=0;i<t;i++)
cout<<b[i][0]+1<<" "<<b[i][1]+1<<endl;
}

int main()
{
input();
solve();
return 0;
}

but cannot answer this test:
4
3 1 1 1

i think you should change it

see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-11-23 04:26:24Online Contester Team © 2002 - 2016. All rights reserved.