Problem:
Fractional Knapsack Problem
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
The total value of the items is as large as possible.
The total weight of the selected items is at most $W$.
You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Constraints
$1 \le N \le 10^5$
$1 \le W \le 10^9$
$1 \le v_i \le 10^9 (1 \le i \le N)$
$1 \le w_i \le 10^9 (1 \le i \le N)$
Sample Input 1
3 50
60 10
100 20
120 30
Sample Output 1
240
When you put 10 of item $1$, 20 of item $2$ and 20 of item $3$, the total value is maximized.
Sample Input 2
3 50
60 13
100 23
120 33
Sample Output 2
210.90909091
When you put 13 of item $1$, 23 of item $2$ and 14 of item $3$, the total value is maximized. Note some outputs can be a real number.
Sample Input 3
1 100
100000 100000
Sample Output 3
100

Submitted solutions:

code_snippet: #define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;

typedef struct items{
    int v;
    int w;
    float r;
    int s=0;

}it;

int main (){
    int n, c, tw=0;
    double sum=0;
    it x[100000];

    cin >> n >> c;

    for(int i=0; i<n; i++){
        cin >> x[i].v >> x[i].w;
        x[i].r = (float)x[i].v/x[i].w;
    }

    sort(x, x + n, [](const it &a,const it &b){
        return a.r > b.r;
    });
    

    for(int i=0; i<n; i++){

        
        if(x[i].w < c-tw){
            sum+= x[i].v;
            tw += x[i].w;
        }
        else if (x[i].w >= c-tw){
            sum+= x[i].v*((double)(c-tw)/x[i].w);
            break;
        }
    }

    if(sum == int(sum)) cout << (int) sum << endl;
    else cout << fixed << setprecision(8) << sum << endl;

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5108
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define Kareem              \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
using namespace std;
#define int long long
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define msb(x) (63 - __builtin_clzll(x))
#define lsb(x) (__builtin_ctzll(x))
#define bit_count(x) (__builtin_popcountll(x))
int di[] = {0,  0,  1, -1,  1,  1, -1, -1};
int dj[] = {1, -1, 0,  0,  1, -1,  1, -1};
//          R   L  D   U   DR DL   UR  UL
const int M=1e9+7;
const int N=1e5+5;
void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve()
{
    int n,w;cin>>n>>w;
    int v[n],weight[n];
    vector<pair<double,int>>percent(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i]>>weight[i];
        percent[i].second=i;
        percent[i].first=double(v[i])/weight[i];
    }
    sort(rall(percent));
    double ans=0;
    for (int i = 0; i < n; i++)
    {
        int item=percent[i].second;
        if(weight[item]<=w){
            ans+=v[item];
            w-=weight[item];
        }else{
            ans+=double(v[item]*w)/weight[item];
            break;
        }
    }
    cout<<fixed<<setprecision(8)<<ans<<'\n';
}
signed main()
{
    Kareem;
    //file();
    //int tc;cin>>tc;while(tc--)
    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6132
final_rank: 2

code_snippet: /**
 *    author:  MOAZ_KING
 *    created: 01.11.2025 16:02:25
**/
#include <bits/stdc++.h>
#define double long double
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n, w;
  cin >> n >> w;
  vector<pair<double, double>> v(n);
  for (auto& [a, b] : v) {
    cin >> a >> b;
  }
  sort(v.begin(), v.end(),
  [] (auto a, auto b) {
    auto x = a.first / a.second;
    auto y = b.first / b.second;
    return x > y;
  });
  double ans = 0;
  for (auto& [a, b] : v) {
    if (w >= b) {
      ans += a;
      w -= b;
    } else {
      ans += (w / b) * a;
      break;
    }
  }
  cout << fixed << setprecision(9) << ans;
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 6168
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct item{
    long double v,w,r;
};

bool comp (item i1, item i2)
{
    return (i1.r>i2.r);
}

int main()
{
    int n,cap;
    cin >> n>>cap;
    item arr[n+5];
    for (int i=0;i<n;i++)
    {
        cin >> arr[i].v >>arr[i].w ;
        arr[i].r = (arr[i].v/arr[i].w);
    }

    sort (arr,arr+n,comp);

   long double profit=0;

    for (int i=0;i<n;i++)
    {
        if (arr[i].w<=cap)
        {
            profit += arr[i].v;
            cap-= arr[i].w ;
        }
        else {
            profit+= cap*arr[i].r;
            break;
        }
    }
    cout <<fixed<<setprecision(10)<< profit <<endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 8120
final_rank: 12

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

struct item
{

    double price, weight, unitprice;
};

bool comp(item item1, item item2)
{
    return item1.unitprice > item2.unitprice;
}

int main()
{
    int N;
    double cap;
    cin>>N>>cap;
    item arr[N+5];
    for(int i=0; i<N; i++)
    {
        cin>>arr[i].price>>arr[i].weight;
        arr[i].unitprice = arr[i].price / arr[i].weight;
    }
    sort(arr, arr+N, comp);
    double profit=0;
    for(int i=0; i<N; i++)
    {
        if(arr[i].weight<=cap)
        {
            cap = cap-arr[i].weight;
            profit = profit+ arr[i].price;
        }
        else
        {
            profit += (cap*arr[i].unitprice);
            break;
        }

    }
    printf("%.10lf", profit);
}
accuracy: 1
time_ms: 70
memory_kb: 5808
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
// using mint = modint1000000007;
// using mint = double;
#endif
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c)
#define repsq(i, n) for (ll i = 1; ((i) * (i) < n); ++i)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define len(x) (int)(x).size()
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define uniq(vec) sort(all(vec)); vec.erase(unique(all(vec)),end(vec))
#define rev(vec) reverse(vec.begin(), vec.end())
#define each(x, a) for(auto& x : a)
#define elif else if
#define pb push_back
#define eb emplace_back
#define lexi lexicographical_compare
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define Test int t; cin >> t; while(t--)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define dbg(...) cout << #__VA_ARGS__ << " = ", _print(__VA_ARGS__)
#define sint(...) int __VA_ARGS__; in(__VA_ARGS__)
#define sll(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define sstr(...) string __VA_ARGS__; in(__VA_ARGS__)
#define sch(...) char __VA_ARGS__; in(__VA_ARGS__)
#define sdbl(...) double __VA_ARGS__; in(__VA_ARGS__)
#define sld(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define svll(n, v) vll v(n); scan(v)
#define svii(n, v) vii v(n); scan(v)
#define svec(type, n, v) vector<type> v(n); scan(v)
#define s1vll(n,v) vll v(n + 1); rep(i, 1, n + 1) cin >> v[i];
#define s1vii(n,v) vii v(n + 1); rep(i, 1, n + 1) cin >> v[i];
// ----------------------------------------------------------------------------------------
#define FLUSH cin.ignore(numeric_limits<streamsize>::max(), '\n') //Forget whatever is there in the current line and go to the next line. Use cin.ignore() for ignorning the very next character.
#define avoidBlanks while (cin.peek() == '\n') cin.ignore()
// ----------------------------------------------------------------------------------------
//binarySearch macros
// ----------------------------------------------------------------------------------------
#define lb(v,target) lower_bound(all(v), target)
#define rlb(v,target) lower_bound(rall(v), target)
#define lbset(s,target) s.lower_bound(target)
#define ub(v,target) upper_bound(all(v), target)
#define lbidx(v,target) lb(v,target)-v.begin()
#define ubidx(v,target) ub(v,target)-v.begin()
#define rub(v,target) upper_bound(rall(v), target) //Equivalent to finding the largest element smaller than or equal to target
#define ubset(s,target) s.upper_bound(target)
//vector macros
#define ins(v,idx, value) (v).insert((v).begin() + (idx), value)
//for inserting an elem at an index in the vector
#define voc(str) (std::vector<std::decay_t<decltype(str[0])>>((str).begin(), (str).end()))
#define vjoin(v1, v2) (v1.insert(v1.end(), v2.begin(), v2.end()))
#define rotatel(v, k) rotate((v).begin(), (v).begin() + ((k) % (v).size()), (v).end())
#define rotater(v, k) rotate((v).rbegin(), (v).rbegin() + ((k) % (v).size()), (v).rend())
// ----------------------------------------------------------------------------------------
//math macros
#define manhdist(x1,y1,x2,y2) abs(x1-x2)+abs(y1-y2)
#define digitcount(n) ((n) == 0 ? 1 : (int)log10(abs(n)) + 1)
#define cdiv(a, b) (((a) + (b) - 1) / (b))
// ----------------------------------------------------------------------------------------
//string macros
#define str(x) to_string(x)
#define tolower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)

// ----------------------------------------------------------------------------------------
//array macros
#define cleantable(m,v) memset(m,v,sizeof(m));
// ----------------------------------------------------------------------------------------
//character macros
#define ctoi(c) ((c) - '0')
// ----------------------------------------------------------------------------------------
//bit macros
#define bit(x, i) (((x) >> (i)) & 1)
#define popcount(x) __builtin_popcountll(x)
#define lsb(x) ((x) & -(x))
//
#define print_range(v, i, j) copy((v).begin() + (i), (v).begin() + (j), ostream_iterator<decltype((v)[0])>(cout, " "))

//
const int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

// ----------------------------------------------------------------------------------------
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vch = vector<char>;
using vvcc = vector<vch>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pdd = pair<long double, long double>;
using pii = pair<int, int>;
using vvll = vector<vll>;
using vii = vector<int>;
using vvii = vector<vii>;
using vecs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvpii = vector<vpii>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vpll = vector<pair<ll, ll>>;
using vpci = vector<pair<char,int>>;
using vpcl = vector<pair<char,ll>>;
using vvpll = vector<vpll>;
using vbl = vector<bool>;
using vvbl = vector<vector<bool>>;
using usetii = unordered_set<int>;
using usetll = unordered_set<ll>;
using setii = set<int>;
using setll = set<ll>;
using setpll = set<pll>;
using setpii = set<pii>;
using setstr = set<string>;
using usetpll = unordered_set<pll>;
using usetpii = unordered_set<pii>;
using stkint = stack<int>;
using stkll = stack<ll>;
using stkpii = stack<pii>;
using stkpll = stack<pll>;
static constexpr ll inf  = 1000000000000000000LL;
static constexpr ll ninf  = -1000000000000000000LL;
// ----------------------------------------------------------------------------------------
template<class T> auto vmin(const T& a){ return *min_element(all(a)); }
template<class T> auto vmax(const T& a){ return *max_element(all(a)); }
template<class T> void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> void chmax(T& a, T b) { if (a < b) a = b; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }
template<typename T>
using maxpq = priority_queue<T>;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

 
//scan
inline void scan() {}
inline void scan(int &a) { std::cin >> a; }
inline void scan(unsigned &a) { std::cin >> a; }
inline void scan(long &a) { std::cin >> a; }
inline void scan(long long &a) { std::cin >> a; }
inline void scan(unsigned long long &a) { std::cin >> a; }
inline void scan(char &a) { std::cin >> a; }
inline void scan(float &a) { std::cin >> a; }
inline void scan(double &a) { std::cin >> a; }
inline void scan(long double &a) { std::cin >> a; }
inline void scan(std::vector<bool> &vec) {
    for (int32_t i = 0; i < vec.size(); i++) {
        int a;
        scan(a);
        vec[i] = a;
    }
}
inline void scan(std::string &a) { std::cin >> a; }
template <class T>
inline void scan(std::vector<T> &vec);
template <class T, size_t size>
inline void scan(std::array<T, size> &vec);
template <class T, class L>
inline void scan(std::pair<T, L> &p);
template <class T, size_t size>
inline void scan(T (&vec)[size]);
template <class T>
inline void scan(std::vector<T> &vec) {
    for (auto &i : vec) scan(i);
}
template <class T>
inline void scan(std::deque<T> &vec) {
    for (auto &i : vec) scan(i);
}
template <class T, size_t size>
inline void scan(std::array<T, size> &vec) {
    for (auto &i : vec) scan(i);
}
template <class T, class L>
inline void scan(std::pair<T, L> &p) {
    scan(p.first);
    scan(p.second);
}
template <class T, size_t size>
inline void scan(T (&vec)[size]) {
    for (auto &i : vec) scan(i);
}
template <class T>
inline void scan(T &a) {
    std::cin >> a;
}
inline void in() {}
template <class Head, class... Tail>
inline void in(Head &head, Tail &...tail) {
    scan(head);
    in(tail...);
}
 
//print
inline void print() { std::cout << ' '; }
inline void print(const bool &a) { std::cout << a; }
inline void print(const int &a) { std::cout << a; }
inline void print(const unsigned &a) { std::cout << a; }
inline void print(const long &a) { std::cout << a; }
inline void print(const long long &a) { std::cout << a; }
inline void print(const unsigned long long &a) { std::cout << a; }
inline void print(const char &a) { std::cout << a; }
inline void print(const char a[]) { std::cout << a; }
inline void print(const float &a) { std::cout << a; }
inline void print(const double &a) { std::cout << a; }
inline void print(const long double &a) { std::cout << a; }
inline void print(const std::string &a) {
    for (auto &&i : a) print(i);
}
template <class T>
inline void print(const std::vector<T> &vec);
template <class T, size_t size>
inline void print(const std::array<T, size> &vec);
template <class T, class L>
inline void print(const std::pair<T, L> &p);
template <class T, size_t size>
inline void print(const T (&vec)[size]);
template <class T>
inline void print(const std::vector<T> &vec) {
    if (vec.empty()) return;
    print(vec[0]);
    for (auto i = vec.begin(); ++i != vec.end();) {
        std::cout << ' ';
        print(*i);
    }
}
template <typename T>
inline void print(const std::set<T>& s) {
    if (s.empty()) return;
    auto it = s.begin();
    print(*it);
    for (++it; it != s.end(); ++it) {
        cout << ' ';
        print(*it);
    }
}

template <class T>
inline void print(const std::deque<T> &vec) {
    if (vec.empty()) return;
    print(vec[0]);
    for (auto i = vec.begin(); ++i != vec.end();) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T, size_t size>
inline void print(const std::array<T, size> &vec) {
    print(vec[0]);
    for (auto i = vec.begin(); ++i != vec.end();) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T, class L>
inline void print(const std::pair<T, L> &p) {
    print(p.first);
    std::cout << ' ';
    print(p.second);
}
template <class T, size_t size>
inline void print(const T (&vec)[size]) {
    print(vec[0]);
    for (auto i = vec; ++i != end(vec);) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T>
inline void print(const T &a) {
    std::cout << a;
}
inline void out() { std::cout << '\n'; }
template <class T>
inline void out(const T &t) {
    print(t);
    std::cout << '\n';
}
template <class Head, class... Tail>
inline void out(const Head &head, const Tail &...tail) {
    print(head);
    std::cout << ' ';
    out(tail...);
}

template<typename T>
void __print(const T &x) { cout << x; }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cout << "{"; __print(x.first); cout << ", "; __print(x.second); cout << "}";
}

template<typename T>
void __print(const vector<T> &v) {
    cout << "[";
    for (size_t i = 0; i < v.size(); ++i) {
        __print(v[i]);
        if (i + 1 != v.size()) cout << ", ";
    }
    cout << "]";
}

template<typename T>
void __print(const set<T> &v) {
    cout << "{";
    bool first = true;
    for (auto &i : v) {
        if (!first) cout << ", ";
        __print(i);
        first = false;
    }
    cout << "}";
}

template<typename T>
void __print(const multiset<T> &v) { __print(set<T>(v.begin(), v.end())); }

template<typename K, typename V>
void __print(const map<K, V> &v) {
    cout << "{";
    bool first = true;
    for (auto &i : v) {
        if (!first) cout << ", ";
        __print(i);
        first = false;
    }
    cout << "}";
}

template<typename T>
void __print(const unordered_set<T> &v) { __print(set<T>(v.begin(), v.end())); }

template<typename K, typename V>
void __print(const unordered_map<K, V> &v) { __print(map<K, V>(v.begin(), v.end())); }

void _print() { cout << endl; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cout << ", ";
    _print(v...);
}
//redefined find template to give -1 if key not found.
template<typename Container, typename Key>
inline int find_idx(const Container &c, const Key &key) {
    auto it = std::find(std::begin(c), std::end(c), key);
    if (it == std::end(c)) return -1;
    return int(std::distance(std::begin(c), it));
}

template<typename T, typename Func>
T bitwise_bs(T start, int maxpow, Func works, bool maximise = true) {
    T cur = start;
    for (T step = (1LL << maxpow); step > 0; step >>= 1) {
        if (maximise) {
            if (works(cur + step)) cur += step;
        } else {
            if (works(cur - step)) cur -= step;
        }
    }
    return cur;
}



struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
} iosetup;

const int residues[] = {1, 7, 11, 13, 17, 19, 23, 29};

vll primes_upto(ll n) 
{
    if (n < 2) return {};

    bitset<50000001> is_prime;
    is_prime.set();
    is_prime[0] = 0; // 1 is not prime

    vll primes = {2, 3, 5};

    int sqrt_n = sqrt(n);

    for (int p = 7; p <= sqrt_n; p += 2) {
        // Check only numbers coprime to 2, 3, 5
        ll mod30 = p % 30;
        bool good = false;
        each(r,residues)
            if (r == mod30) good = true;

        if (!good) continue;
        if (!is_prime[p/2]) continue;

        for (int j = p*p; j <= n; j += 2*p) {
            is_prime[j/2] = 0;
        }
    }

    for (int p = 7; p <= n; p += 2) {
        int mod30 = p % 30;
        each(r,residues) {
            if (mod30 == r) {
                if (is_prime[p/2]) primes.push_back(p);
                break;
            }
        }
    }

    return primes;
}
ll power(ll a, ll b) 
{
    ll result = 1;
    while (b > 0) {
        if (b % 2 == 1) result *= a;
        a *= a;
        b /= 2;
    }
    return result;
}

string to_base(ll a,ll b)
{
  if (b<2 || b>36) throw invalid_argument("base out of range");
    if (a == 0) return "0";
    static const char* digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string s;
    while (a > 0) {
        int rem = a % b;
        s.pb(digits[rem]);
        a /= b;
    }
    reverse(all(s));
    return s;
}

template <typename T>
std::vector<T> vslice(const std::vector<T>& v, int l, int r) {
    if (l < 0) l += v.size();  // Handle negative indexing like Python
    if (r < 0) r += v.size();
    l = std::max(0, l);
    r = std::min((int)v.size(), r);
    if (l > r) l = r;  // Avoid invalid range
    return std::vector<T>(v.begin() + l, v.begin() + r);
}


vll all_divisors(ll n) {
    vll divs;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            divs.push_back(i);
            if (i != n / i) divs.push_back(n / i);
        }
    }
    sort(all(divs));
    return divs;
}

vll pqtop(priority_queue<ll>pq,ll k)
{
  vll res;
  while (k-- && !pq.empty()) {
    res.pb(pq.top());
    pq.pop();
  }
  return res;
}

//Classic template

template <typename F>
ll bsta(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    ll x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}



struct pair_hash {
    size_t operator()(const pll& p) const {
        return hash<ll>()(p.first) ^ (hash<ll>()(p.second) << 1);
    }
};
inline string toLowerCopy(const string &s) {
    string t = s;
    transform(t.begin(), t.end(), t.begin(), ::tolower);
    return t;
}

int main() 
{
    sll(n,w);
    vector<long double> val(n),wei(n);
    vector<long double>per(n);
    vector<vector<long double>> item;
    rep(n)
    {
        in(val[i],wei[i]);
        per[i] = (long double)val[i]/(long double)wei[i];
        item.pb({per[i],val[i],wei[i]});
    }
    sort(all(item),greater<>());
    long double ans = 0;
    rep(i,0,n)
    {
        long double used = min(item[i][2],(long double)w);
        ans += item[i][0] * used;
        w-=used;
    }
    
    out(ans);
    
    
}
accuracy: 1
time_ms: 50
memory_kb: 16556
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>


using namespace std;
using ll = long long;

int main() {
    int n;
    ll w;
    cin >> n >> w;

	vector<tuple<double, ll, ll>> items(n);
    for (int i = 0; i < n; i++) {
		cin >> get<1>(items[i]) >> get<2>(items[i]);
        get<0>(items[i]) = (double)(get<1>(items[i])) / get<2>(items[i]);
    }
    sort(items.begin(), items.end(), [](auto& a, auto& b) {
        return get<0>(a) > get<0>(b);
        });

   
    double wKnapsack = 0;
    double totalValue = 0;
	int i = 0;
    while ((wKnapsack < w) && (i != n)) {
		double ratio = get<0>(items[i]);
        ll value = get<1>(items[i]);
		ll Wt = get<2>(items[i]);

        if (Wt + wKnapsack <= w) {
			wKnapsack += Wt;
            totalValue += value;
        }
        else {
			totalValue += (w - wKnapsack) * ratio;
            wKnapsack = w;
        }
        i++;
    }

    cout.precision(10);
    cout << fixed << totalValue << '\n';
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5420
final_rank: 7

code_snippet: #include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    int n;
    ll capacity;
    cin >> n >> capacity;

    vector<ll> w(n), v(n);
    vector<pair<double, int>> r;

    for (int i = 0; i < n; ++i) {
        cin >> v[i] >> w[i];
        double ratio = static_cast<double>(v[i]) / w[i];
        r.push_back({ratio, i});
    }

    sort(r.begin(), r.end());

    double value = 0.0;

    for (int i = n - 1; i >= 0 && capacity > 0; --i) {
        int idx = r[i].second;
        if (w[idx] <= capacity) {
            value += v[idx];
            capacity -= w[idx];
        } else {
            value += r[i].first * capacity;
            capacity = 0;
        }
    }

    cout << fixed << setprecision(10) << value << endl;
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 6708
final_rank: 9

code_snippet: #include <stdio.h>
#include <stdlib.h>

// 品物の情報を保持する構造体
typedef struct {
    long long value;
    long long weight;
    double density; // 重さ1あたりの価値
} Item;

// qsortで密度を降順にソートするための比較関数
int compareItems(const void *a, const void *b) {
    Item *itemA = (Item *)a;
    Item *itemB = (Item *)b;
    if (itemA->density < itemB->density) {
        return 1;
    } else if (itemA->density > itemB->density) {
        return -1;
    }
    return 0;
}

int main() {
    int N;
    long long W;
    scanf("%d %lld", &N, &W);

    Item *items = (Item *)malloc(sizeof(Item) * N);

    for (int i = 0; i < N; i++) {
        scanf("%lld %lld", &items[i].value, &items[i].weight);
        items[i].density = (double)items[i].value / items[i].weight;
    }

    // 価値密度で品物を降順にソート
    qsort(items, N, sizeof(Item), compareItems);

    double total_value = 0.0;

    // 価値密度が高い順にナップサックに詰めていく
    for (int i = 0; i < N; i++) {
        if (W == 0) {
            break; // ナップサックが満杯
        }
        
        // 品物iを詰める量を決める
        // ナップサックの残り容量と品物の重さのうち、小さい方
        long long take_weight = (items[i].weight < W) ? items[i].weight : W;
        
        // 詰めた分だけ価値を合計に加算
        total_value += (double)take_weight * items[i].density;
        
        // ナップサックの残り容量を減らす
        W -= take_weight;
    }

    printf("%.12f\n", total_value);

    free(items);

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7112
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip> // std::setprecision
using namespace std;

struct Item {
    double value; // 価値
    double weight; // 重さ
    double value_per_weight; // 価値/重さの比
};

// 比較用関数
bool compare(const Item &a, const Item &b) {
    return a.value_per_weight > b.value_per_weight; // 高いものから順に
}

int main() {
    int N;  // 品物の数
    long long W;  // ナップサックの容量
    cin >> N >> W;

    vector<Item> items(N);

    // 入力を受け取る
    for (int i = 0; i < N; i++) {
        cin >> items[i].value >> items[i].weight;
        items[i].value_per_weight = items[i].value / items[i].weight;
    }

    // 価値/重さの比で降順に並べ替える
    sort(items.begin(), items.end(), compare);

    double total_value = 0; // 最大の価値の合計

    for (int i = 0; i < N; i++) {
        if (W == 0) break; // ナップサックがいっぱいになった場合

        if (W >= items[i].weight) {
            // その品物をすべて詰めることができる
            W -= items[i].weight;
            total_value += items[i].value;
        } else {
            // ナップサックに入る分だけ詰める
            total_value += items[i].value_per_weight * W;
            W = 0; // ナップサックがいっぱいになったので終了
        }
    }

    // 結果の出力（小数点以下6桁まで表示）
    cout << fixed << setprecision(6) << total_value << endl;

    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5456
final_rank: 10

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


int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int n, w; cin >> n >> w;
    vector<pair<int, int>> itm(n);
    for(auto &x:itm) cin >> x.first >> x.second;

    auto cmp = [](const auto &a, const auto &b) {
        return (double)a.first/a.second >(double)b.first/b.second;
    };
    sort(itm.begin(), itm.end(), cmp);
    int i=0; double res = 0.0;
    int curcap = w;
    for(int i=0;i<n;i++) {
        if(itm[i].second<=curcap) {
            res+= itm[i].first; curcap-= itm[i].second;
        } else {
            res += (1.0 *itm[i].first/itm[i].second*curcap);
            break;
        }
    }
    if((res-(int) res) < 1e-7) cout << (int) res << '\n';
    else printf("%.8lf\n", res);


    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3868
final_rank: 1

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

struct Item{
    double weight;
    double profit;
    double ratio;
    int index;
};

int main(){
    int n;
    cin>>n;
    vector<Item> items(n);
    double capacity;
    cin>>capacity;
    for(int i=0; i<n; i++){
        //cin>>items[i].weight>>items[i].profit;
        cin>>items[i].profit>>items[i].weight;
        items[i].ratio = items[i].profit/items[i].weight;
        items[i].index = i;
    }

    //double capacity = 50;
    //cin>>capacity;
    sort(items.begin(), items.end(), [](const Item &a, const Item &b){
         return a.ratio > b.ratio;});

    vector<double>x(n,0.0);
    double total = 0.0;
    double remaining = capacity;

    for(int i=0; i<n; ++i){
        if(items[i].weight <=remaining){
            x[i] = 1.0;
            total += items[i].profit;
            remaining -= items[i].weight;
        }
        else{
            x[i] = remaining/items[i].weight;
            total += x[i]*items[i].profit;
            remaining = 0;
            break;
        }
    }

    cout<<setprecision(15)<<total;
}
accuracy: 0.34
time_ms: 40
memory_kb: 5376
final_rank: 16

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

struct Item{
    double weight;
    double profit;
    double ratio;
    int index;
};

int main(){
    int n;
    cin>>n;
    vector<Item> items(n);
    double capacity;
    cin>>capacity;
    for(int i=0; i<n; i++){
        //cin>>items[i].weight>>items[i].profit;
        cin>>items[i].profit>>items[i].weight;
        items[i].ratio = items[i].profit/items[i].weight;
        items[i].index = i;
    }

    //double capacity = 50;
    //cin>>capacity;
    sort(items.begin(), items.end(), [](const Item &a, const Item &b){
         return a.ratio > b.ratio;});

    vector<double>x(n,0.0);
    double total = 0.0;
    double remaining = capacity;

    for(int i=0; i<n; ++i){
        if(items[i].weight <=remaining){
            x[i] = 1.0;
            total += items[i].profit;
            remaining -= items[i].weight;
        }
        else{
            x[i] = remaining/items[i].weight;
            total += x[i]*items[i].profit;
            remaining = 0;
            break;
        }
    }

    cout<<setprecision(9)<<total;
}
accuracy: 0.34
time_ms: 40
memory_kb: 5372
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
 bool comp(pair<int,int>a,pair<int,int>b){
    return a.first*b.second>b.first*a.second;
}
   
int main()
{   
    
    int c,n;
    cin>>n>>c;
        vector<int>val(n);
        vector<int>wt(n);
        for(int i=0;i<n;i++){
            cin>>val[i]>>wt[i];
        }
        
        vector<pair<int,int>>items;

        for(int i=0;i<val.size();i++){
            items.emplace_back(val[i],wt[i]);
        }

        sort(items.begin(),items.end(),comp);

          double profit=0;
        for(int i=0;i<val.size();i++){
            if(items[i].second>c){
 double vw=((double)items[i].first/(double)items[i].second)*(c*1.00);
                profit+=vw;
                break;
            } 
            if(items[i].second<=c) {profit+=items[i].first;
            c-=items[i].second;}
            if(c==0) break;
        }
        cout<<setprecision(1000000)<<profit<<endl;

    
}
accuracy: 0.34
time_ms: 30
memory_kb: 7256
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve()
{
    ll n, w;
    cin >> n >> w;
    vector<pair<pair<double, double>, double>> vec(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> vec[i].first.first >> vec[i].first.second;
        vec[i].second = vec[i].first.first / vec[i].first.second;
    }
    auto comp = [] (pair<pair<double, double>, double> a, pair<pair<double, double>, double> b) {
        return a.second >= b.second;
    };
    sort(vec.begin(), vec.end(), comp);
    double ans = 0;
    for (auto it: vec) {
        double val = it.second;
        double amt = it.first.second;
        if (amt <= w) {
            ans += (amt * val);
            w -= amt;
        }
        else {
            ans += (((double)w) * val);
            w = 0;
        }
    }
    cout << setprecision(10) << fixed << ans << "\n";
}

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5428
final_rank: 5

code_snippet: // nur_008
// بِسْمِ اللَّهِ الرَّحْمَـٰنِ الرَّحِيمِ
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = double;
bool cmp(pair<int, pair<int, ld>> a, pair<int, pair<int, ld>> b)
{
    return a.second.second > b.second.second;
}
void champ()
{
    ll n, m;
    cin >> n >> m;
    ld taka = 0;
    vector<pair<ll, pair<ll, ld>>> vp;
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        ld w = (ld)x / (ld)y;
        vp.push_back({x, {y, w}});
    }
    sort(vp.begin(), vp.end(), cmp);
    int i = 0;
    // for (auto [a, b] : vp)
    // {
    //     cout << a << " " << b.first << " " << b.second << " \n";
    // }
    while (m>0 && i < n)
    {
        ll mini = min(m, vp[i].second.first);
        taka += (ld)mini * vp[i].second.second;
        m -= mini;
        vp[i].second.first -= mini;
        if (vp[i].second.first == 0)
            i++;
    }
    ll money = taka;
    if (money == taka)
    {
        cout << money << "\n";
    }
    else
        cout << fixed << setprecision(8) << taka << "\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        champ();
    }
    return 0;
    //    اللّٰهُ أَكْبَر
}
accuracy: 1
time_ms: 20
memory_kb: 7368
final_rank: 4