Submission #753102

#TimeUsernameProblemLanguageResultExecution timeMemory
753102abysmalJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
99 ms10048 KiB
#include<iostream> #include<stdio.h> #include<stdint.h> #include<iomanip> #include<algorithm> #include<utility> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<deque> #include<math.h> #include<assert.h> using namespace std; const int64_t INF = 1e18 + 5; const int64_t mINF = 1e9 + 5; const int64_t MOD = 1e9 + 7; const int nbit = 31; const int nchar = 26; const int D = 4; int dr[D] = {1, -1, -1, 1}; int dc[D] = {1, 1, 1, -1}; struct Thing { int val; int id; Thing(int val_, int id_) : val(val_), id(id_) {} bool operator < (const Thing& o) const { return val < o.val; } }; struct Solution { int n; vector<Thing> a; vector<int> b; Solution() {} void solve() { cin >> n; b.resize(n, 0); for(int i = 0; i <= n; i++) { int x; cin >> x; a.push_back(Thing(x, i)); } for(int i = 0; i < n; i++) { cin >> b[i]; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector<int> prefix(n + 1, 0); for(int i = 1; i <= n; i++) { int dif = a[i - 1].val - b[i - 1]; prefix[i] = max(prefix[i - 1], max(dif, 0)); } int suf = 0; vector<int> ans(n + 1, -1); for(int i = n; i >= 0; i--) { int id = a[i].id; ans[id] = max(suf, prefix[i]); int tmp = 0; if(i != 0) tmp = max(a[i].val - b[i - 1], 0); suf = max(suf, tmp); } for(int i = 0; i <= n; i++) { cout << ans[i] << " "; } } int modadd(int t1, int t2) { int res = t1 + t2; if(res >= MOD) res -= MOD; return res; } int Abs(int tmp) { if(tmp < 0) return -tmp; return tmp; } int64_t MASK(int j) { return (1LL << j); } bool BIT(int64_t tmp, int j) { return (tmp & MASK(j)); } }; void __setup() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); } int main() { __setup(); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { Solution().solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...