# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198070 | AryaKnight | Pod starim krovovima (COCI20_psk) | C++14 | 3 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mul(int a,int b)
{
return ((a)*1ll*(b))%mod;
}
void add(int &a,int b)
{
a+=b;
if(a>=mod)a-=mod;
}
int sub(int a,int b){
a-=b;
if(a<0){
a+=mod;
}
return a;
}
int powz(int a,int b)
{
int res=1;
while(b)
{
if(b&1){
res=mul(res,a);
}
b/=2;
a=mul(a,a);
}
return res;
}
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
input>>x.F>>x.S;
return input;
}
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
for(auto& i:x)
input>>i;
return input;
}
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
for(auto& i:x)
output<<i<<' ';
return output;
}
const int N=1000002;
void solve(){
int n;
cin>>n;
vector<int>a(n);
vector<pi>b(n);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i].F;
b[i].S=i;
}
sort(all(a));
sort(all(b));
ll sum=0,sum2=accumulate(all(a),0ll);
for(int i=0;i<n;i++){
sum+=b[i].F;
}
for(int i=0;i<n;i++){
if(sum-b[i].F>=sum2){
sum-=b[i].F;
}
else{
vector<int>ans(n);
cout<<i<<"\n";
for(int j=i;j<n;j++){
if(b[j].F<sum2){
ans[b[j].S]=b[j].F;
sum2-=b[j].F;
}
else{
ans[b[j].S]=sum2;
sum2=0;
}
}
for(int j=0;j<n;j++){
cout<<ans[j]<<' ';
}
return;
}
}
cout<<n<<"\n";
for(int i=0;i<n;i++){
cout<<0<<' ';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc=1;
//~cin>>tc;
for(int _=0;_<tc;_++){
//~ cout<<"Case #"<<_+1<<": ";
solve();
if(_!=tc-1)
cout<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |