Submission #931923

#TimeUsernameProblemLanguageResultExecution timeMemory
931923lovrotArt Exhibition (JOI18_art)C++17
100 / 100
175 ms23048 KiB
#include <cstdio> 
#include <algorithm> 
#include <cstring> 
#include <cmath> 
#include <iostream> 
#include <set> 
#include <queue> 
#include <deque> 
#include <vector> 
#include <random> 
#include <chrono> 

#define X first
#define Y second
#define PB push_back
#define EB emplace_back

using namespace std; 

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MOD = 1e9 + 7; // 998 244 353;
const int N = 5e5 + 10; 
const ll OO = 1e18;

int n, I[N]; 
ll A[N], B[N];

ll prf, xam = -OO, ans; 

int main() {
	scanf("%d", &n); 
	for(int i = 0; i < n; ++i) {
		scanf("%lld%lld\n", A + i, B + i); 
		I[i] = i;
	}
	sort(I, I + n, [](int a, int b) { return A[a] < A[b]; });
	for(int i = 0; i < n; ++i) {
		xam = max(xam, -prf + A[I[i]]);
		prf += B[I[i]];
		ans = max(ans, prf - A[I[i]] + xam);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

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