On the existence of local and global Lagrangians for ordinary differential equations