# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
511456 | Jean7 | Pod starim krovovima (COCI20_psk) | C++14 | 1 ms | 332 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>
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std ;
bool cmp ( pair<pair<int,int>,int> x , pair<pair<int,int>,int> y )
{
if ( x.first.second == y.first.second ) return x.first.first > y.first.first ;
return x.first.second > y.first.second ;
}
bool com ( pair<pair<int,int>,int> x , pair<pair<int,int>,int> y )
{
return x.second < y.second ;
}
int32_t main ()
{
fio
int n , ans = 0 ;
cin >> n ;
pair <pair<int,int>,int> a[n] ;
for ( int i = 0 ; i < n ; i++ )
{
cin >> a[i].first.first ;
cin >> a[i].first.second ;
a[i].second = i ;
}
sort ( a , a+n , cmp ) ;
int i = 0 , j = n-1 ;
while ( i < j )
{
int k = a[i].first.second - a[i].first.first ;
if ( k > a[j].first.first )
{
a[i].first.first += a[j].first.first ;
a[j].first.first = 0 ;
j-- ;
}
else if ( k < a[j].first.first )
{
a[i].first.first += k ;
i++ ;
a[j].first.first -= k ;
}
else if ( k == a[j].first.first )
{
a[i].first.first += k ;
i++ ;
a[j].first.first = 0 ;
j-- ;
}
}
for ( auto it : a ) if ( it.first.first == 0 ) ans++ ;
cout << ans << "\n" ;
sort ( a , a+n , com ) ;
for ( auto it : a ) cout << it.first.first << " " ;
return 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |