Submission #833849

#TimeUsernameProblemLanguageResultExecution timeMemory
833849BilAktauAlmansurDivide and conquer (IZhO14_divide)C++17
100 / 100
226 ms5948 KiB
#include <bits/stdc++.h> #pragma optimize ("g",on) #pragma GCC optimize ("inline") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma comment(linker, "/stack:200000000") // #define int long long using namespace std; const int N = 1e5 + 7; int n; pair<int, pair<int, int> > a[N]; long long pref_d[N], pref_x[N]; signed main() { // freopen("bank.in", "r", stdin); // freopen("bank.out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); cin>>n; for(int i = 1; i <= n; i++) { int pos, d, x; cin>>pos>>d>>x; a[i].first = pos, a[i].second.first = d, a[i].second.second = x; } sort(a + 1, a + 1 + n); for(int i = 1; i <= n; i++) { pref_d[i] = pref_d[i - 1] + a[i].second.first; pref_x[i] = pref_x[i - 1] + a[i].second.second; } long long ans = 0; for(int i = 1; i <= n; i++) { for(int j = i; j <= min(i + 1000, n); j++) { long long sum_x = pref_x[j] - pref_x[i - 1], sum_d = pref_d[j] - pref_d[i - 1]; int len = a[j].first - a[i].first; if(len <= sum_x) { ans = max(ans, sum_d); } } for(int j = n; j >= max(i, n - 1000); j--) { long long sum_x = pref_x[j] - pref_x[i - 1], sum_d = pref_d[j] - pref_d[i - 1]; int len = a[j].first - a[i].first; if(len <= sum_x) { ans = max(ans, sum_d); } } } cout << ans << '\n'; }

Compilation message (stderr)

divide.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize ("g",on)
      | 
divide.cpp:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    8 | #pragma comment(linker, "/stack:200000000")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...