#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//template<typename T>
//using oset = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
/*** Typedef ***/
typedef int ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef long double ld;
//typedef unordered_set<ll> usll;
typedef unordered_multiset<ll,ll> umsll;
/* Special functions:
find_by_order(k) --> returns iterator to the kth largest element counting from 0
order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/
/*** Loops ***/
#define ffit(i, dat) for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
#define fr(i,a,b) for(ll i = a; i <= b; i++)
#define f(i,a,b) for(ll i = a; i < b; i++)
#define F(i,a,b) for(ll i = b-1; i >= a; i--)
#define ff3(i,a,b,m) for(ll i = a; i <b; i+=m)
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define ipar(ar,n) vll ar(n); ff1(i,0,n) cin>>ar[i];
#define op(x) cout<<x<<kl;
#define ol(x) cout<<x<<" ";
#define vo(ar,n) f(i,0,n) cout<<ar[i]<<" ";
/*** Define Values ***/
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15
/*** STLs ***/
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define cu continue
#define br break
#define rsz resize
#define ins insert
#define ft front
#define bk back
#define bb begin
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define ff first
#define ss second
#define rr return
#define sqr(x) (x)*(x)
#define nxt next_permutation
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))
#define MN3(n1,n2,n3) min(n1,min(n2,n3))
#define MN4(n1,n2,n3,n4) min(n1,min(n2,min(n3,n4)))
#define MX3(n1,n2,n3) max(n1,max(n2,n3))
#define MX4(n1,n2,n3,n4) max(n1,max(n2,max(n3,n4)))
#define mxar(a,n) *max_element(a,a+n)
#define mnar(a,n) *min_element(a,a+n)
#define arr_sm(a,n) accumulate(a,a+n,0)
#define vc_sm(ve) accumulate(ve.begin(),ve.end(),0)
#define mx_vc(ve) *max_element(ve.begin(),ve.end())
#define mn_vc(ve) *min_element(ve.begin(),ve.end())
//#define endl " \n"
/*** STLs ***/
typedef vector <ll> vll;
#define vvll vector<vll>
typedef set <ll> sll;
typedef multiset <ll> msll;
//typedef multimap <ll> mpll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll, ll> > vpll;
typedef set <pair <ll, ll> > spll;
typedef priority_queue <pair <ll, ll> > pqpll;
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ml unordered_map<ll,ll>
///typedef unordered_multiset<int> umsi;
typedef unordered_set<ll> us;
///vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.
/*** Sorts ***/
#define czero(n) __builtin_popcountll(n) // count the number of 1's in the bit representation of a number
#define cenzero(n) __builtin_ctzll(n) // count the number of zereos from the end of the bit representation of a number until a 1
#define countbegzero(n) __builtin_clzxll(n)
#define checkparity(n) __builtin_parityll(n)// checks whether the number of bits are even or odd
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtgrt(v) sort(all(v), greater<ll>())
#define prsrt greater<pair<int,int>>()
/*** Some Prints ***/
#define ip(n) ll n; cin>>n;
#define is(s) string s; cin>>s;
#define ic(s) char s; cin>>s;
#define in(n) cin>>n;
#define inn(n,m) cin>>n>>m;
#define ipp(n,k) ll n; cin>>n; ll k; cin>>k;
#define ip3(n,m,k) ll n; cin>>n;ll m;cin>>m; ll k; cin>>k;
#define kl '\n'
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": ";
#define ps(x,y) fixed<<setprecision(y)<<x
#define inf 1e9+5
#define w(x) ll x; cin>>x; while(x--)
#define go(i, a) for (auto &i : a)
#define go1(it, v) for(auto it = v.begin(); it != v.end(); ++it)
//#define mk(arr,n,type) type *arr=new type[n];
#define sz(obj) (int(obj.size()))
#define vii(vc,n) vll vc(n+5); f(i,1,n+1){cin>>vc[i];}
#define vi(vc,n) vll vc; f(i,0,n){ip(x);vc.pb(x);}
#define vI(vc,n) f(i,0,n){ip(x);vc.pb(x);}
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define depressed() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//bool ans = all_of(arr, arr + 6, [](int x) {return x & 1; } );
const double pi = 3.141592653589793238460;
template<typename T,typename T1>T ama(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amm(T &a,T1 b){if(b<a)a=b;return a;}
#define TRC
#ifdef TRC
#define trc(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
//use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trc(...)
#endif
#define mod 1000000007
const ll N = 105;
ll dx[4]={0, 0, +1, -1};
ll dy[4]={+1, -1, 0, 0};
bool cmp(pair<pll,ll>a, pair<pll,ll>b){
if(a.ff>b.ff){
rr 1;
}
if(a.ff<b.ff){
rr 0;
}
if(a.ff.ss>b.ff.ss){
rr 1;
}
rr 0;
}
void fun()
{
ip(n);
vector<pair<pll,ll>>v;
f1(n){
ipp(x,y);
v.pb({{y,x},i});
}
sort(all(v),cmp);
ll i = 0 , j = sz(v)-1;
ll ct = 0;
while(i<j){
ll d = v[i].ff.ff-v[i].ff.ss;
ll dd = v[j].ff.ss;
if(d>dd){
v[i].ff.ss+=dd;
v[j].ff.ss =0;
j--;
ct++;
}
else if(d<dd){
v[j].ff.ss = dd-d;
v[i].ff.ss = v[i].ff.ff;
i++;
}
else{
v[j].ff.ss = 0;
v[i].ff.ss = v[i].ff.ff;
j--;
i++;
ct++;
}
}
op(ct);
ll a[n+5];
go(i,v){
a[i.ss] = i.ff.ss;
}
f1(n){
ol(a[i]);
}
}
int32_t main()
{
// tasklist
// taskkill /f /im solution.exe
depressed();
ll t = 1;
//cin>>t;
while(t--)
{
fun();
}
//cer;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |