제출 #699676

#제출 시각아이디문제언어결과실행 시간메모리
699676Mohamed_Kachef06Art Exhibition (JOI18_art)C++17
0 / 100
0 ms212 KiB

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define A first
#define B second
signed main(){
   int n;
   cin >> n;
   pair<int , int> p[n+1];
   for (int i = 1 ; i<=n ; i++){
      int a , b;
      cin >> a >> b;
      p[i] = {a , b};
   }
   sort(p , p+n+1);
   for (int i = 1 ; i<=n ; i++){
      p[i].B += p[i-1].B;
   }
   int max = 0 , maxind = 0, min = 1e9;
   for (int i = 1 ; i<=n ; i++){
        if (p[i].B - p[i].A >= max)  { max = p[i].B - p[i].A; maxind =i ;}
   }
   for (int i = 1 ; i<=maxind ; i++){
    if (p[i-1].B - p[i].A < min) min = p[i-1].B - p[i].A;
   }
   cout << max - min << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...