#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b//コストの型(いじる必要なし) struct Kruskal{ struct edge{ int from,to; T cost; int used; edge(int from,int to,T cost): from(from),to(to),cost(cost),used(0){} bool operator<(const edge& e) const{ return cost siz,par; vector es; Kruskal(){} Kruskal(int n):n(n),siz(n,1),par(n){ iota(par.begin(),par.end(),0); } //UF int root(int x){ return (x==par[x]?x:(par[x]=root(par[x]))); } bool sameParent(int x,int y){ return (root(x)==root(y)); } void unite(int x,int y){ x=root(x);y=root(y); if(x==y) return; if(siz[x]>n; int s=n; ll c[n],d[n],sum=0; rep(i,n){ cin>>c[i]>>d[i]; sum+=c[i]; } Kruskal g(n+1); rep(i,n) g.add_edge(s,i,c[i]); rep(i,n-1) g.add_edge(i,i+1,d[i+1]); cout<