Submission #347303

#TimeUsernameProblemLanguageResultExecution timeMemory
347303CaroLindaJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
416 ms18668 KiB
#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(),x.end() #define sz(x) (int)(x.size() ) const int MAXN = 2e5+10 ; using namespace std ; int N ; int C[MAXN] , employees[MAXN] ; pair<int,int> neckties[MAXN] ; int main() { scanf("%d", &N) ; for(int i = 1 ; i <= N+1 ; i++ ) { scanf("%d", &neckties[i].first ) ; neckties[i].second = i ; } sort(neckties+1, neckties + 2 + N ) ; for(int i= 1 ; i <= N ; i++ ) scanf("%d", &employees[i] ) ; sort(employees+1, employees + 1 + N ) ; multiset< int > s ; for(int i = 1 ; i <= N ; i++ ) s.insert( -max( neckties[i+1].first - employees[i] , 0 ) ) ; for(int i=1 ; i <= N+1 ; i++ ) { C[ neckties[i].second ] = -*s.begin() ; if( i == N+1 ) break ; auto it = s.find( -max(neckties[i+1].first - employees[i] , 0 ) ) ; s.erase( it ) ; s.insert( -max(neckties[i].first - employees[i] , 0 ) ) ; } for(int i = 1 ; i <= N+1 ; i++ ) printf("%d ", C[i] ) ; printf("\n") ; }

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d", &N) ;
      |  ~~~~~^~~~~~~~~~
ho_t1.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%d", &neckties[i].first ) ;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.cpp:26:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  for(int i= 1 ; i <= N ; i++ ) scanf("%d", &employees[i] ) ;
      |                                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...