Submission #6873093


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);
#define debug(x , y) cerr << #x << " = " << x << y ;

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , k , a , b ;
deque < pair < int , int > > vec ;
map < int , int > mp ;

bool cmp( pair < int , int > s , pair < int , int > f ){
 return  s.second > f.second ;
}

int main(){

 cin >> n >> k ;
 forn( int , i , 0 , n ){
   cin >> a >> b ;
   if( a <= k ) vec.pb( { a , b } ) ;
 }

 sort( all( vec ) , cmp ) ;

 forn( int , i , 0 , k ){
    mp[ i ] = k - i - 1 ;
 }

 bool op = 1 ;
 ll sum = 0 ;
 while( op ){
    if( sz( vec ) ){
        map < int , int > ::iterator it ;
        bool x = 0 ;
        for( it = mp.begin() ; it != mp.end() ; it++ ){
            if( vec.front().first + (*it).second <= k ){
                    sum += vec.front().second , mp.erase( it ) ;
                    vec.pop_front();
                    x = 1 ;
                    break ;
            }
        }
        if( !x ) op = 0 ;
    } else op = 0 ;
 }

 cout << sum ;

 return 0 ;
}

/*
A B C D
Don't put topic on Problem try to divide the problem to subproblem and solve each one and try successfully to merge them
try to solve A , B in 30 min as possible
If their is subtask try to solve the second one first if the constraints are only differ
Read all Problem so you could find an ex that you can solve fast
A -- don't write big code focus again
B -- greedy , math , bit mask , tricks , DP
C -- solve A , B first then solve C but fast as possible
greedy
DP
binary search
DFS , BFS , DSU( detect a cycle , make sets )
bit mask
number theory , math
meet in the middle
focus on the problem and constraints.
*/

Submission Info

Submission Time
Task D - Summer Vacation
User mahmoud_acm
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2847 Byte
Status WA
Exec Time 2103 ms
Memory 5760 KB

Compile Error

./Main.cpp: In function ‘void File_input(std::string)’:
./Main.cpp:25:43: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     freopen( pathIn.c_str(), "r", stdin ) ;
                                           ^
./Main.cpp: In function ‘void File_output(std::string)’:
./Main.cpp:29:45: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     freopen( pathOut.c_str(), "w", stdout ) ;
                                             ^

Judge Result

Set Name All Sample
Score / Max Score 0 / 400 0 / 0
Status
AC × 9
WA × 7
TLE × 5
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 2 ms 256 KB
sample_03 AC 1 ms 256 KB
testcase_01 AC 1977 ms 3200 KB
testcase_02 AC 150 ms 1920 KB
testcase_03 WA 1419 ms 1792 KB
testcase_04 TLE 2103 ms 5760 KB
testcase_05 TLE 2103 ms 5760 KB
testcase_06 AC 59 ms 2048 KB
testcase_07 TLE 2103 ms 5632 KB
testcase_08 AC 26 ms 1920 KB
testcase_09 AC 88 ms 3968 KB
testcase_10 AC 194 ms 5760 KB
testcase_11 TLE 2103 ms 5248 KB
testcase_12 WA 1194 ms 1664 KB
testcase_13 TLE 2103 ms 5760 KB
testcase_14 WA 80 ms 5376 KB
testcase_15 WA 7 ms 640 KB
testcase_16 WA 88 ms 5760 KB
testcase_17 WA 19 ms 1024 KB
testcase_18 WA 417 ms 5760 KB