This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma comment(linker,"/STACK:36777216")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <cassert>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>
#include <stdexcept>
#include <cfloat>
using namespace std;
#define LET(x,a) ::typeid(a) x(a)
#define IFOR(i,a,b) for(LET(i,a);i!=(b);++i)
#define EACH(it,v) IFOR(it,v.begin(),v.end())
#define FOR(i,a,b) for(int i = (a); i < int(b);i++)
#define REP(i,n) FOR(i,0,n)
#define SZ size()
#define PB push_back
#define PF push_front
#define V(x) vector< x >
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0
#define swap(x,y) x ^=y ^= x^=y
#define ALL(v) (v).begin(),(v).end()
#define DBN1(a) cerr<<#a<<"="<<(a)<<"\n"
const double pi = acos(-1.0);
const double eps = 1e-11;
const int oo = 0x3f3f3f3f;
template<class T> inline void checkmin(T &a, T b){ if (b<a) a = b; }
template<class T> inline void checkmax(T &a, T b){ if (b>a) a = b; }
template<class T> inline T sqr(T x){ return x*x; }
typedef pair<int, int> ipair;
template<class T> inline T lowbit(T n){ return (n ^ (n - 1))&n; }
template<class T> inline int countbit(T n){ return (n == 0) ? 0 : (1 + countbit(n&(n - 1))); }
template<class T> inline T gcd(T a, T b) { T c; while (a != 0) { c = a; a = b%a; b = c; } return b; }
template<class T> inline T mabs(T a) { if (a < 0) return -a; else return a; }
typedef V(int) VI;
typedef V(VI) VII;
typedef V(string) VS;
typedef long long int64;
typedef long double LD;
typedef pair<int, int> PI;
typedef pair<double, double> PD;
const int N = (int) 5e5+111;
const int MOD = (int) 1e9+7;
typedef struct art {
int64 A,B;
int ind;
art() {
A = B = 0LL;
ind = -1;
}
bool operator < (const art &o) const {
if(A != o.A) return (A < o.A);
else return (ind < o.ind);
}
} art;
art a[N];
int64 cB[N];
inline int solve(int testnum)
{
int n; scanf("%d",&n);
REP(i,n) {
scanf("%lld%lld", &a[i].A, &a[i].B);
a[i].ind = i;
}
sort(a,a+n);
cB[0] = a[0].B;
FOR(i,1,n) cB[i] = cB[i-1] + a[i].B;
int64 extra = -a[0].A;
FOR(l,1,n) checkmin(extra, cB[l-1] - a[l].A);
int64 res = -1e18;
REP(r,n) checkmax(res, cB[r] - a[r].A - extra);
printf("%lld\n", res);
return 0;
}
int main(int argc, char* argv[])
{
#ifdef LocalHost
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
int t = 1; //scanf("%d", &t);
if (argc > 1) t = atoi(argv[1]);
FOR(_t, 1, t + 1) {
int ret = ::solve(_t);
if (ret == -1) {
// cerr << "Failed test #" << _t << endl;
break;
}
//cerr << "Solved test #" << _t << endl;
}
#ifdef LocalHost
printf("Time taken : %.10f seconds\n", (1.0f*clock()) / CLOCKS_PER_SEC);
#endif
return 0;
}
Compilation message (stderr)
art.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker,"/STACK:36777216")
^
art.cpp: In function 'int solve(int)':
art.cpp:92:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int n; scanf("%d",&n);
^
art.cpp:94:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &a[i].A, &a[i].B);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |