Submission #1060388

# Submission time Handle Problem Language Result Execution time Memory
1060388 2024-08-15T13:36:17 Z khanhtb Just Long Neckties (JOI20_ho_t1) C++14
0 / 100
2 ms 4700 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7; 
const ll inf = 2e18;
const ll B = 320;
const ll N = 2e5+8;
ll n,b[N],ans[N];
pair<ll,ll> a[N];
void solve(){
    cin >> n;
    multiset<ll> s;
    for(ll i = 1; i <= n+1; i++) cin >> a[i].fi, a[i].se = i;
    for(ll i = 1; i <= n; i++) cin >> b[i];
    sort(a+1,a+n+2),sort(b+1,b+n+1);
    for(ll i = 1; i <= n; i++){
        s.insert(abs(a[i+1].fi - b[i]));
    }
    for(ll i = 1; i <= n+1; i++){
        ans[a[i].se] = *s.rbegin();
        s.erase(s.find(abs(a[i+1].fi - b[i])));
        s.insert(abs(a[i].fi - b[i]));
    }
    for(ll i = 1; i <= n+1; i++) cout << ans[i] << " ";
} 
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }   
    ll T = 1;
    // cin >> T;
    for (ll i = 1; i <= T; i++) {
        solve();
        cout << '\n';
    }
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -