题解:[XRCOI Round 1] 相聚相逢本无意
首先我们先特判掉两种情况,一种是
判断完这两种情况,我们考虑计算其他情况。由于要求
(与出题人讨论了若干种细节,给出题人弄红温了。)
Code
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
#define mk make_pair
#define reaD read
#define raed read
#define haed head
#define cotu cout
#define se second
#define fi first
#define itn int
using namespace std;
bool Mst;
const int Max=2e5+10;
const int mod=998244353;
const int inf=1e9+10;
inline int read(){
int res=0,v=1;
char c=getchar();
while(c<'0'||c>'9'){v=(c=='-'?-1:1);c=getchar();}
while(c>='0'&&c<='9'){res=(res<<3)+(res<<1)+(c^48);c=getchar();}
return res*v;
}
struct po{
int x,y;
po(int x=0,int y=0):
x(x),y(y){;}
bool operator <(const po a)const{
return x<a.x;
}
}a[Max];
vector<int>ans;
bool Med;
signed main(){
int n=read();
int z=0;
for(int i=1;i<=n;++i){
int x,y;
x=read();
y=read();
if(y!=0)++z;
a[i]=po(x,y);
}
sort(a+1,a+1+n);
int j=0;
if(a[1].x==0&&a[1].y!=0&&z==1){
cout << a[1].y << '\n';
for(int i=1;i<=a[1].y;++i){
cout << "100000 ";
}
return 0;
}
if(a[1].x==0&&a[1].y>0&&z>1){
cout << "-1\n";
return 0;
}
for(int i=1;i<=n;++i){
int z=0;
for(int j=i;j<=n;++j){
if(a[j].y){
z=1;
break;
}
}
if(!z)break;
if(j!=a[i].x){
while(j<a[i].x){
ans.push_back(j);
++j;
}
--a[i].y;
}
if(a[i].y<0){
cout << "-1\n";
return 0;
}
while(a[i].y){
ans.push_back(j-1);
--a[i].y;
}
}
cout << ans.size() << "\n";
for(int i:ans){
cout << i << ' ';
}
cout << "\n";
cerr<< "Time: "<<clock()/1000.0 << "s\n";
cerr<< "Memory: " << (&Mst-&Med)/1000000.0 << "MB\n";
return 0;
}