Submission #291961

#TimeUsernameProblemLanguageResultExecution timeMemory
291961jbroeksteegArt Exhibition (JOI18_art)C++14
100 / 100
350 ms48380 KiB
#include <iostream> #include <climits> #include <numeric> #include <cassert> #include <algorithm> #include <queue> #include <map> #include <stack> #include <set> #include <vector> #include <array> #include <memory> #define IN(a,b) (a.find(b) != a.end()) #define p(a,b) make_pair(a,b) #define readVec(a) for (int64_t __i = 0; __i<(int64_t)a.size();__i++){cin>>a[__i];} // jimjam template<typename T> void pMin(T &a, T b) {if (b<a){a=b;}} template<typename T> void pMax(T &a, T b) {if (b>a){a=b;}} template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& c); template<typename A, typename B> std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;} template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) { if (c.size() == 0) {os << "{}"; return os;} os << "{" << c[0]; for (int64_t i = 1; i < (int64_t)c.size(); i++) {os <<", "<<c[i];} os << "}"; return os; } using namespace std; int main() { // freopen("input","r",stdin); ios::sync_with_stdio(0); cin.tie(0); int64_t n; cin >> n; vector<pair<int64_t,int64_t>> arts(n); for (int64_t i = 0; i < n; i++) { cin >> arts[i].first >> arts[i].second; } sort(arts.begin(),arts.end()); vector<int64_t> prefixValue(n); prefixValue[0]=arts[0].second; for (int64_t i = 1; i < n; i++) { prefixValue[i] = prefixValue[i-1] + arts[i].second; } multiset<int64_t> before; int64_t ans=0; for (int64_t i = 0; i < n; i++) { if (before.size()) { // idk do calculations int64_t thisValue = prefixValue[i] - arts[i].first; // cout << "i=" << i << ": " << thisValue-*before.begin() << endl; pMax(ans,thisValue-*before.begin()); pMax(ans,prefixValue[i] - (arts[i].first - arts[0].first)); } // add to set if (i+1<n) before.insert(prefixValue[i] - arts[i+1].first); } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...