Submission #1167839

#TimeUsernameProblemLanguageResultExecution timeMemory
1167839SmuggingSpunDivide and conquer (IZhO14_divide)C++20
48 / 100
13 ms328 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; typedef long long ll; const int lim = 1e5 + 5; template<class T>void maximize(T& a, T b){ if(a < b){ a = b; } } struct Data{ int x, g, d; bool operator <(const Data& other){ return this->x < other.x; } }; int n; Data a[lim]; namespace sub12{ void solve(){ sort(a + 1, a + n + 1); ll ans = 0; for(int i = 1; i <= n; i++){ ll gold = 0, energy = 0; for(int j = i; j <= n; j++){ gold += a[j].g; if((energy += a[j].d) >= a[j].x - a[i].x){ maximize(ans, gold); } } } cout << ans; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i].x >> a[i].g >> a[i].d; } if(n <= 5000){ sub12::solve(); } }

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:38:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...