이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct Item{
int profit, weight, copy;
Item() {
profit = 0;
weight = 0;
copy = 0;
}
Item(int profit, int weight, int copy){
this->profit=profit;
this->weight=weight;
this->copy=copy;
}
};
static bool cmp(struct Item a, struct Item b){
double r1=(double)a.profit/(double)a.weight;
double r2=(double)b.profit/(double)b.weight;
return r1>r2;
};
int knap(int W, struct Item arr[], int N){
sort(arr, arr+N, cmp);
int finalValue=0;
for(int i=0; i<N; i++){
while(arr[i].weight<=W&&arr[i].copy>0){
W-=arr[i].weight;
finalValue+=arr[i].profit;
arr[i].copy--;
}
}
return finalValue;
};
int main(){
int w,n;
cin>>w>>n;
Item arr[n];
for (int i=0; i<n; i++){
cin>>arr[i].profit>>arr[i].weight>>arr[i].copy;//input array arr dgn struct item
}
cout<<knap(w, arr, n);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |