106B - Choosing Laptop - CodeForces Solution


brute force implementation *1000

Please click on ads to support us..

Python Code:


tests = int(input())
laptops = []
for i in range(1, tests + 1):
    speed, ram, hdd, cost = [int(x) for x in input().split()]
    laptops.append((cost, i, speed, ram, hdd))

outdated = set()
for k, (c, i, s, r, h) in enumerate(laptops):
    for l, (cc, ii, ss, rr, hh) in enumerate(laptops):
        if k != l:
            if s < ss and r < rr and h < hh:
                outdated.add((c, i, s, r, h))

resu = []
for l in laptops:
    if l not in outdated:
        resu.append(l)

resu = sorted(resu)

print(resu[0][1])

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
int main () {
    std::ios::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll n,m=1001,ans;
    cin>>n;
    ll a[n],b[n],c[n],x[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i]>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]<a[j]&&b[i]<b[j]&&c[i]<c[j]){
                x[i]=1001;
                break;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(x[i]<m){
            m=x[i];
            ans=i+1;
        }
    }
    cout<<ans;
}


Comments

Submit
0 Comments
More Questions

429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array