結果

問題 No.3681 心の沸騰石
コンテスト
ユーザー kuronosu1024
提出日時 2026-09-05 13:44:23
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 356µs
コード長 7,096 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,047 ms
コンパイル使用メモリ 342,376 KB
実行使用メモリ 9,756 KB
最終ジャッジ日時 2026-09-05 13:48:29
合計ジャッジ時間 3,639 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifndef INCLUDED_MAIN
#define INCLUDED_MAIN

#include __FILE__

int main(void){
    ll r,p,q; cin >> r >> p >> q;
    ll a,b,c,d; cin >> a >> b >> c >> d;

    ll ans = 0;

    vector<ll> v = {a,b,c};
    sort(all(v));

    a=v[2]; b=v[1]; c=v[0];

    {
        int u;
        u = min(c, r/p);
        r -= u*p;
        a-=u;
        b-=u;
        c-=u;
        ans += u;
    }
    {
        int u;
        u = min({b, r/(p+q), (a-b)+d});
        r -= u*(p+q);
        ans += u;
        a-=u;
        b-=u;
        if(d >= u){
            d-=u;
            u=0;
        }else{
            u-=d;
            d=0;
        }
        a-=u;
    }
    {
        int u;
        u = min({a, r/(p+q*2), d/2});
        r -= u*(p+q*2);
        ans += u;
        a-=u;
        d-=u*2;
    }
    {
        int u;
        u = min(d/3, r/(p+q*3));
        ans += u;
    }
    cout << ans << "\n";
}

#else
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld=  long double;
#define rep(i,n) for(i=0;i<(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

namespace nskr{
    template<typename T>
    struct sortedset{
        struct node{
            T key;
            int level;
            node *left, *right;
            int lcount, rcount;
            
            node(T x) :key(x), level(0), left(nullptr), right(nullptr),lcount(0),rcount(0){}
        };
        
        node* sentinel;
        private:
        
        node* root;
        
        node* skew(node* x){ //左同levelを解決
            if(x==nullptr) return nullptr;
            if(x->left==nullptr) return x;
            if(x->left->level==x->level){
                node* leftnode = x->left;
                x->left = leftnode->right;
                leftnode->right = x;
                // swap(leftnode->rcount, x->lcount);
                // leftnode->lcount += x->rcount - leftnode->lcount;
                setcount(x);
                setcount(leftnode);
                return leftnode;
            }else{
                return x;
            }
        }
        
        node* split(node* x){ //右連続同levelを解決
            if(x==nullptr) return nullptr;
            if(x->right==nullptr) return x;
            if(x->right->right==nullptr) return x;
            if(x->right->right->level == x->level){
                node* rightnode = x->right;
                x->right = rightnode->left;
                rightnode->left = x;
                rightnode->level++;
                // swap(x->rcount,rightnode->lcount);
                // rightnode->lcount += x->lcount - rightnode->rcount;
                setcount(x);
                setcount(rightnode);
                return rightnode;
            }else{
                return x;
            }
        }

        void setcount(node* x){
            if(x==nullptr) return;
            if(x->left == nullptr) x->lcount = 0;
            else x->lcount = x->left->lcount + x->left->rcount + 1;
            if(x->right == nullptr) x->rcount = 0;
            else x->rcount = x->right->lcount + x->right->rcount + 1;
            x->rcount+=0;
            return;
        }
        
        node* insert(node* x, T key){
            if(x == nullptr) return new node(key);
            if(x->key < key){
                x->right = insert(x->right, key);
            }else if(x->key > key){
                x->left  = insert(x->left , key);
            } else return x;
            setcount(x);
            return split(skew(x));
        }

        node* erase(node* x, T key){
            if(x == nullptr) return nullptr;
            if(key < x->key) {
                x-> left = erase(x->left, key);
            }else if(key > x->key) x->right=erase(x->right, key);
            else{
                if(x->left == nullptr){
                    node* ret = x->right;
                    delete x;
                    return ret;
                }
                if(x->right == nullptr){
                    node* ret = x->left;
                    delete x;
                    return ret;
                }
                node* tgt = x->right;
                while(tgt->left != nullptr) tgt = tgt->left;
                x->key = tgt->key;
                x->right = erase(x->right, tgt->key);
            }
            setcount(x);
            
            int newlevel = min(
                (x->left == nullptr ? 0 : x->left->level),
                (x->right == nullptr ? 0 : x->right->level)    
            )+1;

            if(newlevel < x->level){
                x->level = newlevel;
                if(x->right != nullptr && newlevel < x->right->level){
                    x->right->level = newlevel; 
                }
            }

            x = skew(x);
            if(x->right != nullptr){
                x->right = skew(x->right);
                if(x->right->right != nullptr) x->right->right = skew(x->right->right);
            }

            x = split(x);
            if(x->right != nullptr) x->right = split(x->right);

            return x;
        }



        node* get(node* x, int t){
            if(x==nullptr) return nullptr;
            if(x->lcount < t) return get(x->right, t-x->lcount-1);
            if(x->lcount > t) return get(x->left, t);
            return x;
        }

        node* lower_bound(node* x, T key){//key以上の最小
            if(x == nullptr)return sentinel;
            if(x->key < key){
                return lower_bound(x->right, key);
            }if(x->key > key){
                node* ret = lower_bound(x->left, key);
                if(ret == sentinel) return x;
                else return ret;
            }
            return x;
        }

        node* upper_bound(node* x, T key){//key以下の最大
            if(x == nullptr)return sentinel;
            if(x->key > key){
                return upper_bound(x->left, key);
            }if(x->key < key){
                node* ret = upper_bound(x->right, key);
                if(ret == sentinel) return x;
                else return ret;
            }
            return x;
        }

    
        int rank(node* x, T key){
            if(x==nullptr) return 0;
            if(x->key==key) return  x->lcount+1;
            if(x->key<key){
                return rank(x->right,key) + x->lcount+1;
            }
            if(x->key>key){
                return rank(x->left,key);
            }
        }
        
        public:


        
        sortedset():root(nullptr),sentinel(0){}
        
        const T operator[](int t){
            node* x = get(root, t);
            if(x==nullptr) return T();
            else return x->key;
        }

        size_t size(){
            if(root==nullptr)return 0;
            return root->lcount + root->rcount + 1;
        }

        void insert(T key){root = insert(root, key);}
        void erase(T key){root = erase(root, key);}
        
        node* lower_bound(T key){return lower_bound(root,key);}
        node* upper_bound(T key){return upper_bound(root,key);}

        int rank(T key){return rank(root,key);}
    };
}



#endif
0