답안 #813609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813609 2023-08-08T00:30:00 Z farhan132 학교 설립 (IZhO13_school) C++17
100 / 100
96 ms 18792 KB
/***Farhan132***/
// #pragma GCC optimize("Ofast,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
 
const ll mod =  (ll) 998244353;
// const ll mod =  (ll) 1e9 + 7;
const ll inf = numeric_limits<int>::max()-5;
const ll INF = (ll)2e18;
 
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll N = 3e5 + 5;

void solve(){

    vector < ii > a;

    ll n, m, s; cin >> n >> m >> s;

    vector < ll > vis(n + 1, 0);

    for(ll i = 1; i <= n; i++){
        ll x, y; cin >> x >> y;
        a.pb({x, y});
    }
    priority_queue < ll > p1, p2, p3;
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    for(ll i = 0; i < m; i++){
        ans += a[i].ff; 
        p1.push(a[i].ss - a[i].ff);
    }
    vector < ii > b;
    for(ll i = m; i < n; i++){
        b.pb({a[i].ss, a[i].ff});
    }
    sort(b.rbegin(), b.rend());
    swap(a, b);
    for(ll i = s; i < a.size(); i++){
        p3.push(a[i].ss);
    }
    for(ll i = s - 1; i >= 0; i--){
        ans += a[i].ff;
        if(p3.size() && a[i].ss < p3.top()){
            p3.push(a[i].ss);
            a[i].ss = p3.top(); p3.pop();
        }
        p2.push(a[i].ss - a[i].ff);
    }
    while(p1.size() && p2.size() && p1.top() + p2.top() > 0){
        ans += p1.top() + p2.top(); p1.pop(); p2.pop();
    }
    cout << ans << '\n';
    
   return;
}

int main() {

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        auto start_time = clock();
    #else
         // freopen("subsequence.in", "r", stdin);
         // freopen("subsequence.out", "w", stdout); 
         ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif

    //precalc();
 
    ll T = 1, CT = 0; //cin >> T; 
 
    while(T--){
        // cout << "Case #" << ++CT << ": ";
        solve();
    }
    
    #ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
    #endif
 
    return 0;
} 

Compilation message

school.cpp: In function 'void solve()':
school.cpp:71:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(ll i = s; i < a.size(); i++){
      |                   ~~^~~~~~~~~~
school.cpp: In function 'int main()':
school.cpp:104:15: warning: unused variable 'CT' [-Wunused-variable]
  104 |     ll T = 1, CT = 0; //cin >> T;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 9 ms 2132 KB Output is correct
14 Correct 26 ms 6236 KB Output is correct
15 Correct 55 ms 11968 KB Output is correct
16 Correct 68 ms 13228 KB Output is correct
17 Correct 68 ms 14896 KB Output is correct
18 Correct 77 ms 15932 KB Output is correct
19 Correct 86 ms 16816 KB Output is correct
20 Correct 96 ms 18792 KB Output is correct