Submission #157777

#TimeUsernameProblemLanguageResultExecution timeMemory
157777ZwariowanyMarcinArt Exhibition (JOI18_art)C++14
100 / 100
275 ms24824 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define mp make_pair #define pb push_back #define ld long double #define ss(x) (int) x.size() #define FOR(i, j, n) for(int i = j; i <= n; ++i) #define fi first #define se second #define cat(x) cerr << #x << " = " << x << endl; #define ios cin.tie(0); ios_base::sync_with_stdio(0) using namespace std; const int nax = 5e5 + 11; int n; pair<ll, int> a[nax]; ll pref[nax]; ll best = -1e18; ll ans = 0; int main() { scanf("%d", &n); FOR(i, 1, n) scanf("%lld %d", &a[i].fi, &a[i].se); sort(a + 1, a + n + 1); FOR(i, 1, n) pref[i] = pref[i - 1] + a[i].se; best = a[1].fi; FOR(i, 1, n) { ans = max(ans, pref[i] + best - a[i].fi); best = max(best, -pref[i] + a[i + 1].fi); } printf("%lld", ans); return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
art.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %d", &a[i].fi, &a[i].se);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...